3 use wcf\data\application\Application
;
4 use wcf\data\option\OptionEditor
;
5 use wcf\data\package\Package
;
6 use wcf\data\package\PackageCache
;
7 use wcf\data\package\PackageEditor
;
8 use wcf\data\page\Page
;
9 use wcf\data\page\PageCache
;
11 use wcf\system\application\ApplicationHandler
;
12 use wcf\system\application\IApplication
;
13 use wcf\system\box\BoxHandler
;
14 use wcf\system\cache\builder\CoreObjectCacheBuilder
;
15 use wcf\system\cache\builder\PackageUpdateCacheBuilder
;
16 use wcf\system\cronjob\CronjobScheduler
;
17 use wcf\system\database\MySQLDatabase
;
18 use wcf\system\event\EventHandler
;
19 use wcf\system\exception\AJAXException
;
20 use wcf\system\exception\ErrorException
;
21 use wcf\system\exception\IPrintableException
;
22 use wcf\system\exception\NamedUserException
;
23 use wcf\system\exception\ParentClassException
;
24 use wcf\system\exception\PermissionDeniedException
;
25 use wcf\system\exception\SystemException
;
26 use wcf\system\language\LanguageFactory
;
27 use wcf\system\package\PackageInstallationDispatcher
;
28 use wcf\system\request\Request
;
29 use wcf\system\request\RequestHandler
;
30 use wcf\system\session\SessionFactory
;
31 use wcf\system\session\SessionHandler
;
32 use wcf\system\style\StyleHandler
;
33 use wcf\system\template\EmailTemplateEngine
;
34 use wcf\system\template\TemplateEngine
;
35 use wcf\system\user\storage\UserStorageHandler
;
36 use wcf\util\FileUtil
;
37 use wcf\util\HeaderUtil
;
38 use wcf\util\StringUtil
;
39 use wcf\util\UserUtil
;
41 // try to set a time-limit to infinite
44 // fix timezone warning issue
45 if (!@ini_get
('date.timezone')) {
46 @date_default_timezone_set
('Europe/London');
49 // define current woltlab suite version
50 define('WCF_VERSION', '3.0.13');
52 // define current unix timestamp
53 define('TIME_NOW', time());
56 if (!defined('NO_IMPORTS')) {
57 require_once(WCF_DIR
.'lib/core.functions.php');
58 require_once(WCF_DIR
.'lib/system/api/autoload.php');
62 * WCF is the central class for the WoltLab Suite Core.
63 * It holds the database connection, access to template and language engine.
66 * @copyright 2001-2017 WoltLab GmbH
67 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
68 * @package WoltLabSuite\Core\System
72 * list of currently loaded applications
75 protected static $applications = [];
78 * list of currently loaded application objects
81 protected static $applicationObjects = [];
84 * list of autoload directories
87 protected static $autoloadDirectories = [];
90 * list of unique instances of each core object
91 * @var SingletonFactory[]
93 protected static $coreObject = [];
96 * list of cached core objects
99 protected static $coreObjectCache = [];
105 protected static $dbObj = null;
109 * @var \wcf\data\language\Language
111 protected static $languageObj = null;
114 * overrides disabled debug mode
117 protected static $overrideDebugMode = false;
121 * @var SessionHandler
123 protected static $sessionObj = null;
127 * @var TemplateEngine
129 protected static $tplObj = null;
132 * true if Zend Opcache is loaded and enabled
135 protected static $zendOpcacheEnabled = null;
138 * force logout during destructor call
141 protected static $forceLogout = false;
144 * Calls all init functions of the WCF class.
146 public function __construct() {
147 // add autoload directory
148 self
::$autoloadDirectories['wcf'] = WCF_DIR
. 'lib/';
150 // define tmp directory
151 if (!defined('TMP_DIR')) define('TMP_DIR', FileUtil
::getTempFolder());
153 // start initialization
155 $this->loadOptions();
156 $this->initSession();
157 $this->initLanguage();
159 $this->initCronjobs();
160 $this->initCoreObjects();
161 $this->initApplications();
162 $this->initBlacklist();
164 EventHandler
::getInstance()->fireAction($this, 'initialized');
168 * Flushes the output, closes the session, performs background tasks and more.
170 * You *must* not create output in here under normal circumstances, as it might get eaten
171 * when gzip is enabled.
173 public static function destruct() {
175 // database has to be initialized
176 if (!is_object(self
::$dbObj)) return;
178 $debug = self
::debugModeIsEnabled(true);
181 if (ob_get_level()) ob_end_flush();
184 // close connection if using FPM
185 if (function_exists('fastcgi_finish_request')) fastcgi_finish_request();
189 if (is_object(self
::getSession())) {
190 if (self
::$forceLogout) {
192 self
::getSession()->delete();
195 self
::getSession()->update();
199 // execute shutdown actions of user storage handler
200 UserStorageHandler
::getInstance()->shutdown();
202 catch (\Exception
$exception) {
203 die("<pre>WCF::destruct() Unhandled exception: ".$exception->getMessage()."\n\n".$exception->getTraceAsString());
208 * Returns the database object.
210 * @return \wcf\system\database\Database
212 public static final function getDB() {
217 * Returns the session object.
219 * @return SessionHandler
221 public static final function getSession() {
222 return self
::$sessionObj;
226 * Returns the user object.
228 * @return \wcf\data\user\User
230 public static final function getUser() {
231 return self
::getSession()->getUser();
235 * Returns the language object.
237 * @return \wcf\data\language\Language
239 public static final function getLanguage() {
240 return self
::$languageObj;
244 * Returns the template object.
246 * @return TemplateEngine
248 public static final function getTPL() {
249 return self
::$tplObj;
253 * Calls the show method on the given exception.
255 * @param \Exception $e
257 public static final function handleException($e) {
258 if (ob_get_level()) {
259 // discard any output generated before the exception occured, prevents exception
260 // being hidden inside HTML elements and therefore not visible in browser output
262 // ob_get_level() can return values > 1, if the PHP setting `output_buffering` is on
263 while (ob_get_level()) ob_end_clean();
265 // `identity` is the default "encoding" and basically means that the client
266 // must treat the content as if the header did not appear in first place, this
267 // also overrules the gzip header if present
268 @header
('Content-Encoding: identity');
269 HeaderUtil
::exceptionDisableGzip();
272 // backwards compatibility
273 if ($e instanceof IPrintableException
) {
278 @header
('HTTP/1.1 503 Service Unavailable');
280 \wcf\functions\exception\
printThrowable($e);
282 catch (\Throwable
$e2) {
283 echo "<pre>An Exception was thrown while handling an Exception:\n\n";
284 echo preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $e2);
285 echo "\n\nwas thrown while:\n\n";
286 echo preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $e);
287 echo "\n\nwas handled.</pre>";
290 catch (\Exception
$e2) {
291 echo "<pre>An Exception was thrown while handling an Exception:\n\n";
292 echo preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $e2);
293 echo "\n\nwas thrown while:\n\n";
294 echo preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $e);
295 echo "\n\nwas handled.</pre>";
301 * Turns PHP errors into an ErrorException.
303 * @param integer $severity
304 * @param string $message
305 * @param string $file
306 * @param integer $line
307 * @throws ErrorException
309 public static final function handleError($severity, $message, $file, $line) {
310 // this is necessary for the shut-up operator
311 if (error_reporting() == 0) return;
313 throw new ErrorException($message, 0, $severity, $file, $line);
317 * Loads the database configuration and creates a new connection to the database.
319 protected function initDB() {
321 $dbHost = $dbUser = $dbPassword = $dbName = '';
323 require(WCF_DIR
.'config.inc.php');
325 // create database connection
326 self
::$dbObj = new MySQLDatabase($dbHost, $dbUser, $dbPassword, $dbName, $dbPort);
330 * Loads the options file, automatically created if not exists.
332 protected function loadOptions() {
333 $filename = WCF_DIR
.'options.inc.php';
335 // create options file if doesn't exist
336 if (!file_exists($filename) ||
filemtime($filename) <= 1) {
337 OptionEditor
::rebuild();
339 require_once($filename);
341 // check if option file is complete and writable
343 if (!is_writable($filename)) {
344 FileUtil
::makeWritable($filename);
346 if (!is_writable($filename)) {
347 throw new SystemException("The option file '" . $filename . "' is not writable.");
351 // check if a previous write operation was incomplete and force rebuilding
352 if (!defined('WCF_OPTION_INC_PHP_SUCCESS')) {
353 OptionEditor
::rebuild();
355 require_once($filename);
361 * Starts the session system.
363 protected function initSession() {
364 $factory = new SessionFactory();
367 self
::$sessionObj = SessionHandler
::getInstance();
368 self
::$sessionObj->setHasValidCookie($factory->hasValidCookie());
372 * Initialises the language engine.
374 protected function initLanguage() {
375 if (isset($_GET['l']) && !self
::getUser()->userID
) {
376 self
::getSession()->setLanguageID(intval($_GET['l']));
380 mb_internal_encoding('UTF-8');
381 if (function_exists('mb_regex_encoding')) mb_regex_encoding('UTF-8');
385 self
::$languageObj = LanguageFactory
::getInstance()->getUserLanguage(self
::getSession()->getLanguageID());
389 * Initialises the template engine.
391 protected function initTPL() {
392 self
::$tplObj = TemplateEngine
::getInstance();
393 self
::getTPL()->setLanguageID(self
::getLanguage()->languageID
);
394 $this->assignDefaultTemplateVariables();
400 * Initializes the user's style.
402 protected function initStyle() {
403 if (isset($_REQUEST['styleID'])) {
404 self
::getSession()->setStyleID(intval($_REQUEST['styleID']));
407 $styleHandler = StyleHandler
::getInstance();
408 $styleHandler->changeStyle(self
::getSession()->getStyleID());
412 * Executes the blacklist.
414 protected function initBlacklist() {
415 $isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
417 if (defined('BLACKLIST_IP_ADDRESSES') && BLACKLIST_IP_ADDRESSES
!= '') {
418 if (!StringUtil
::executeWordFilter(UserUtil
::convertIPv6To4(self
::getSession()->ipAddress
), BLACKLIST_IP_ADDRESSES
)) {
420 throw new AJAXException(self
::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'), AJAXException
::INSUFFICIENT_PERMISSIONS
);
423 throw new PermissionDeniedException();
426 else if (!StringUtil
::executeWordFilter(self
::getSession()->ipAddress
, BLACKLIST_IP_ADDRESSES
)) {
428 throw new AJAXException(self
::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'), AJAXException
::INSUFFICIENT_PERMISSIONS
);
431 throw new PermissionDeniedException();
435 if (defined('BLACKLIST_USER_AGENTS') && BLACKLIST_USER_AGENTS
!= '') {
436 if (!StringUtil
::executeWordFilter(self
::getSession()->userAgent
, BLACKLIST_USER_AGENTS
)) {
438 throw new AJAXException(self
::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'), AJAXException
::INSUFFICIENT_PERMISSIONS
);
441 throw new PermissionDeniedException();
445 if (defined('BLACKLIST_HOSTNAMES') && BLACKLIST_HOSTNAMES
!= '') {
446 if (!StringUtil
::executeWordFilter(@gethostbyaddr
(self
::getSession()->ipAddress
), BLACKLIST_HOSTNAMES
)) {
448 throw new AJAXException(self
::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'), AJAXException
::INSUFFICIENT_PERMISSIONS
);
451 throw new PermissionDeniedException();
456 // handle banned users
457 if (self
::getUser()->userID
&& self
::getUser()->banned
) {
459 throw new AJAXException(self
::getLanguage()->getDynamicVariable('wcf.user.error.isBanned'), AJAXException
::INSUFFICIENT_PERMISSIONS
);
462 self
::$forceLogout = true;
465 if (isset($_COOKIE[COOKIE_PREFIX
.'userID'])) {
466 HeaderUtil
::setCookie('userID', 0);
468 if (isset($_COOKIE[COOKIE_PREFIX
.'password'])) {
469 HeaderUtil
::setCookie('password', '');
472 throw new NamedUserException(self
::getLanguage()->getDynamicVariable('wcf.user.error.isBanned'));
478 * Initializes applications.
480 protected function initApplications() {
481 // step 1) load all applications
482 $loadedApplications = [];
484 // register WCF as application
485 self
::$applications['wcf'] = ApplicationHandler
::getInstance()->getApplicationByID(1);
487 if (!class_exists(WCFACP
::class, false)) {
488 static::getTPL()->assign('baseHref', self
::$applications['wcf']->getPageURL());
491 // start main application
492 $application = ApplicationHandler
::getInstance()->getActiveApplication();
493 if ($application->packageID
!= 1) {
494 $loadedApplications[] = $this->loadApplication($application);
496 // register primary application
497 $abbreviation = ApplicationHandler
::getInstance()->getAbbreviation($application->packageID
);
498 self
::$applications[$abbreviation] = $application;
501 // start dependent applications
502 $applications = ApplicationHandler
::getInstance()->getDependentApplications();
503 foreach ($applications as $application) {
504 if ($application->packageID
== 1) {
508 else if ($application->isTainted
) {
509 // ignore apps flagged for uninstallation
513 $loadedApplications[] = $this->loadApplication($application, true);
516 // step 2) run each application
517 if (!class_exists('wcf\system\WCFACP', false)) {
518 /** @var IApplication $application */
519 foreach ($loadedApplications as $application) {
520 $application->__run();
523 // refresh the session 1 minute before it expires
524 self
::getTPL()->assign('__sessionKeepAlive', SESSION_TIMEOUT
- 60);
529 * Loads an application.
531 * @param Application $application
532 * @param boolean $isDependentApplication
533 * @return IApplication
534 * @throws SystemException
536 protected function loadApplication(Application
$application, $isDependentApplication = false) {
537 $package = PackageCache
::getInstance()->getPackage($application->packageID
);
538 // package cache might be outdated
539 if ($package === null) {
540 $package = new Package($application->packageID
);
542 // package cache is outdated, discard cache
543 if ($package->packageID
) {
544 PackageEditor
::resetCache();
547 // package id is invalid
548 throw new SystemException("application identified by package id '".$application->packageID
."' is unknown");
552 $abbreviation = ApplicationHandler
::getInstance()->getAbbreviation($application->packageID
);
553 $packageDir = FileUtil
::getRealPath(WCF_DIR
.$package->packageDir
);
554 self
::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/';
556 $className = $abbreviation.'\system\\'.strtoupper($abbreviation).'Core';
557 if (class_exists($className) && is_subclass_of($className, IApplication
::class)) {
558 // include config file
559 $configPath = $packageDir . PackageInstallationDispatcher
::CONFIG_FILE
;
560 if (!file_exists($configPath)) {
561 Package
::writeConfigFile($package->packageID
);
564 if (file_exists($configPath)) {
565 require_once($configPath);
568 throw new SystemException('Unable to load configuration for '.$package->package
);
571 // register template path if not within ACP
572 if (!class_exists('wcf\system\WCFACP', false)) {
573 // add template path and abbreviation
574 static::getTPL()->addApplication($abbreviation, $packageDir . 'templates/');
576 EmailTemplateEngine
::getInstance()->addApplication($abbreviation, $packageDir . 'templates/');
578 // init application and assign it as template variable
579 self
::$applicationObjects[$application->packageID
] = call_user_func([$className, 'getInstance']);
580 static::getTPL()->assign('__'.$abbreviation, self
::$applicationObjects[$application->packageID
]);
581 EmailTemplateEngine
::getInstance()->assign('__'.$abbreviation, self
::$applicationObjects[$application->packageID
]);
584 unset(self
::$autoloadDirectories[$abbreviation]);
585 throw new SystemException("Unable to run '".$package->package
."', '".$className."' is missing or does not implement '".IApplication
::class."'.");
588 // register template path in ACP
589 if (class_exists('wcf\system\WCFACP', false)) {
590 static::getTPL()->addApplication($abbreviation, $packageDir . 'acp/templates/');
592 else if (!$isDependentApplication) {
594 static::getTPL()->assign('baseHref', $application->getPageURL());
597 // register application
598 self
::$applications[$abbreviation] = $application;
600 return self
::$applicationObjects[$application->packageID
];
604 * Returns the corresponding application object. Does not support the 'wcf' pseudo application.
606 * @param Application $application
607 * @return IApplication
609 public static function getApplicationObject(Application
$application) {
610 if (isset(self
::$applicationObjects[$application->packageID
])) {
611 return self
::$applicationObjects[$application->packageID
];
618 * Loads an application on runtime, do not use this outside the package installation.
620 * @param integer $packageID
622 public static function loadRuntimeApplication($packageID) {
623 $package = new Package($packageID);
624 $application = new Application($packageID);
626 $abbreviation = Package
::getAbbreviation($package->package
);
627 $packageDir = FileUtil
::getRealPath(WCF_DIR
.$package->packageDir
);
628 self
::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/';
629 self
::$applications[$abbreviation] = $application;
630 self
::getTPL()->addApplication($abbreviation, $packageDir . 'acp/templates/');
634 * Initializes core object cache.
636 protected function initCoreObjects() {
637 // ignore core objects if installing WCF
638 if (PACKAGE_ID
== 0) {
642 self
::$coreObjectCache = CoreObjectCacheBuilder
::getInstance()->getData();
646 * Assigns some default variables to the template engine.
648 protected function assignDefaultTemplateVariables() {
649 self
::getTPL()->registerPrefilter(['event', 'hascontent', 'lang']);
650 self
::getTPL()->assign([
652 '__wcfVersion' => LAST_UPDATE_TIME
// @deprecated 2.1, use LAST_UPDATE_TIME directly
655 $isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
656 // Execute background queue in this request, if it was requested and AJAX isn't used.
658 if (self
::getSession()->getVar('forceBackgroundQueuePerform')) {
659 self
::getTPL()->assign([
660 'forceBackgroundQueuePerform' => true
663 self
::getSession()->unregister('forceBackgroundQueuePerform');
667 EmailTemplateEngine
::getInstance()->registerPrefilter(['event', 'hascontent', 'lang']);
668 EmailTemplateEngine
::getInstance()->assign([
674 * Wrapper for the getter methods of this class.
676 * @param string $name
677 * @return mixed value
678 * @throws SystemException
680 public function __get($name) {
681 $method = 'get'.ucfirst($name);
682 if (method_exists($this, $method)) {
683 return $this->$method();
686 throw new SystemException("method '".$method."' does not exist in class WCF");
690 * Returns true if current application (WCF) is treated as active and was invoked directly.
694 public function isActiveApplication() {
695 return (ApplicationHandler
::getInstance()->getActiveApplication()->packageID
== 1);
699 * Changes the active language.
701 * @param integer $languageID
703 public static final function setLanguage($languageID) {
704 if (!$languageID || LanguageFactory
::getInstance()->getLanguage($languageID) === null) {
705 $languageID = LanguageFactory
::getInstance()->getDefaultLanguageID();
708 self
::$languageObj = LanguageFactory
::getInstance()->getLanguage($languageID);
710 // the template engine may not be available yet, usually happens when
711 // changing the user (and thus the language id) during session init
712 if (self
::$tplObj !== null) {
713 self
::getTPL()->setLanguageID(self
::getLanguage()->languageID
);
714 EmailTemplateEngine
::getInstance()->setLanguageID(self
::getLanguage()->languageID
);
719 * Includes the required util or exception classes automatically.
721 * @param string $className
722 * @see spl_autoload_register()
724 public static final function autoload($className) {
725 $namespaces = explode('\\', $className);
726 if (count($namespaces) > 1) {
727 $applicationPrefix = array_shift($namespaces);
728 if ($applicationPrefix === '') {
729 $applicationPrefix = array_shift($namespaces);
731 if (isset(self
::$autoloadDirectories[$applicationPrefix])) {
732 $classPath = self
::$autoloadDirectories[$applicationPrefix] . implode('/', $namespaces) . '.class.php';
733 if (file_exists($classPath)) {
734 require_once($classPath);
743 public final function __call($name, array $arguments) {
744 // bug fix to avoid php crash, see http://bugs.php.net/bug.php?id=55020
745 if (!method_exists($this, $name)) {
746 return self
::__callStatic($name, $arguments);
749 return $this->$name($arguments);
753 * Returns dynamically loaded core objects.
755 * @param string $name
756 * @param array $arguments
758 * @throws SystemException
760 public static final function __callStatic($name, array $arguments) {
761 $className = preg_replace('~^get~', '', $name);
763 if (isset(self
::$coreObject[$className])) {
764 return self
::$coreObject[$className];
767 $objectName = self
::getCoreObject($className);
768 if ($objectName === null) {
769 throw new SystemException("Core object '".$className."' is unknown.");
772 if (class_exists($objectName)) {
773 if (!is_subclass_of($objectName, SingletonFactory
::class)) {
774 throw new ParentClassException($objectName, SingletonFactory
::class);
777 self
::$coreObject[$className] = call_user_func([$objectName, 'getInstance']);
778 return self
::$coreObject[$className];
783 * Searches for cached core object definition.
785 * @param string $className
788 protected static final function getCoreObject($className) {
789 if (isset(self
::$coreObjectCache[$className])) {
790 return self
::$coreObjectCache[$className];
797 * Returns true if the debug mode is enabled, otherwise false.
799 * @param boolean $ignoreACP
802 public static function debugModeIsEnabled($ignoreACP = false) {
804 if (!$ignoreACP && self
::$overrideDebugMode) {
807 else if (defined('ENABLE_DEBUG_MODE') && ENABLE_DEBUG_MODE
) {
815 * Returns true if benchmarking is enabled, otherwise false.
819 public static function benchmarkIsEnabled() {
820 // benchmarking is enabled by default
821 if (!defined('ENABLE_BENCHMARK') || ENABLE_BENCHMARK
) return true;
826 * Returns domain path for given application.
828 * @param string $abbreviation
831 public static function getPath($abbreviation = 'wcf') {
832 // workaround during WCFSetup
837 if (!isset(self
::$applications[$abbreviation])) {
838 $abbreviation = 'wcf';
841 return self
::$applications[$abbreviation]->getPageURL();
845 * Returns the domain path for the currently active application,
846 * used to avoid CORS requests.
850 public static function getActivePath() {
852 return self
::getPath();
855 return self
::getPath(ApplicationHandler
::getInstance()->getAbbreviation(ApplicationHandler
::getInstance()->getActiveApplication()->packageID
));
859 * Returns a fully qualified anchor for current page.
861 * @param string $fragment
864 public function getAnchor($fragment) {
865 return StringUtil
::encodeHTML(self
::getRequestURI() . '#' . $fragment);
869 * Returns the currently active page or null if unknown.
873 public static function getActivePage() {
874 if (self
::getActiveRequest() === null) {
878 if (self
::getActiveRequest()->getClassName() === CmsPage
::class) {
879 $metaData = self
::getActiveRequest()->getMetaData();
880 if (isset($metaData['cms'])) {
881 return PageCache
::getInstance()->getPage($metaData['cms']['pageID']);
887 return PageCache
::getInstance()->getPageByController(self
::getActiveRequest()->getClassName());
891 * Returns the currently active request.
895 public static function getActiveRequest() {
896 return RequestHandler
::getInstance()->getActiveRequest();
900 * Returns the URI of the current page.
904 public static function getRequestURI() {
905 return preg_replace('~^(https?://[^/]+)(?:/.*)?$~', '$1', self
::getTPL()->get('baseHref')) . $_SERVER['REQUEST_URI'];
909 * Resets Zend Opcache cache if installed and enabled.
911 * @param string $script
913 public static function resetZendOpcache($script = '') {
914 if (self
::$zendOpcacheEnabled === null) {
915 self
::$zendOpcacheEnabled = false;
917 if (extension_loaded('Zend Opcache') && @ini_get
('opcache.enable')) {
918 self
::$zendOpcacheEnabled = true;
923 if (self
::$zendOpcacheEnabled) {
924 if (empty($script)) {
928 opcache_invalidate($script, true);
934 * Returns style handler.
936 * @return StyleHandler
938 public function getStyleHandler() {
939 return StyleHandler
::getInstance();
943 * Returns box handler.
948 public function getBoxHandler() {
949 return BoxHandler
::getInstance();
953 * Returns number of available updates.
957 public function getAvailableUpdates() {
958 $data = PackageUpdateCacheBuilder
::getInstance()->getData();
959 return $data['updates'];
963 * Returns a 8 character prefix for editor autosave.
967 public function getAutosavePrefix() {
968 return substr(sha1(preg_replace('~^https~', 'http', self
::getPath())), 0, 8);
972 * Returns the favicon URL or a base64 encoded image.
976 public function getFavicon() {
977 $activeApplication = ApplicationHandler
::getInstance()->getActiveApplication();
978 $wcf = ApplicationHandler
::getInstance()->getWCF();
980 if ($activeApplication->domainName
!== $wcf->domainName
) {
981 if (file_exists(WCF_DIR
.'images/favicon.ico')) {
982 $favicon = file_get_contents(WCF_DIR
.'images/favicon.ico');
984 return 'data:image/x-icon;base64,' . base64_encode($favicon);
988 return self
::getPath() . 'images/favicon.ico';
992 * Returns true if currently active request represents the landing page.
996 public static function isLandingPage() {
997 if (self
::getActiveRequest() === null) {
1001 return self
::getActiveRequest()->isLandingPage();
1005 * Initialises the cronjobs.
1007 protected function initCronjobs() {
1009 self
::getTPL()->assign('executeCronjobs', CronjobScheduler
::getInstance()->getNextExec() < TIME_NOW
&& defined('OFFLINE') && !OFFLINE
);