-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathApplication.class.php
More file actions
164 lines (143 loc) · 4.85 KB
/
Application.class.php
File metadata and controls
164 lines (143 loc) · 4.85 KB
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
<?php
namespace wcf\data\application;
use wcf\data\DatabaseObject;
use wcf\data\package\Package;
use wcf\data\package\PackageCache;
use wcf\data\package\PackageList;
use wcf\system\application\ApplicationHandler;
use wcf\system\exception\SystemException;
use wcf\system\request\RouteHandler;
use wcf\util\FileUtil;
/**
* Represents an application.
*
* @author Alexander Ebert
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*
* @property-read int $packageID id of the package which delivers the application
* @property-read string $domainName domain used to access the application (may not contain path components, see `$domainPath`)
* @property-read string $domainPath path used to access the application
* @property-read string $cookieDomain domain used to set cookies (corresponds to `domain` cookie property; may not contain path components)
* @property-read 0|1 $isTainted is `1` if the application is being uninstalled and thus should not be loaded during uninstallation, otherwise `0`
* @property-read ?int $landingPageID id of the page that is used as initial page when app is accessed without a controller name
*/
class Application extends DatabaseObject
{
/**
* related package object
* @var Package
*/
protected $package;
/**
* absolute page URL
* @var string
*/
protected $pageURL = '';
/**
* @inheritDoc
*/
protected static $databaseTableIndexName = 'packageID';
/**
* @inheritDoc
*/
protected static $databaseTableIndexIsIdentity = false;
/**
* list of all available application directories
* @var string[]
*/
protected static $directories;
/**
* @inheritDoc
*/
protected function handleData($data)
{
if (isset($data['domainPath'])) {
// The leading and trailing slashes are required and enforced through the admin panel,
// however, some users edit the database directly and omit them, causing incorrect urls.
$data['domainPath'] = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash($data['domainPath']));
}
parent::handleData($data);
}
/**
* @inheritDoc
*/
public function __get(string $name)
{
if (ENABLE_ENTERPRISE_MODE && \defined('ENTERPRISE_MODE_DOMAIN_OVERRIDE') && \PHP_SAPI !== 'cli') {
if (ENTERPRISE_MODE_DOMAIN_OVERRIDE === $_SERVER['HTTP_HOST']) {
if ($name === 'cookieDomain' || $name === 'domainName') {
return ENTERPRISE_MODE_DOMAIN_OVERRIDE;
}
}
}
return parent::__get($name);
}
/**
* Returns the abbreviation of the application.
*
* @return string
*/
public function getAbbreviation()
{
return ApplicationHandler::getInstance()->getAbbreviation($this->packageID);
}
/**
* Returns related package object.
*
* @return Package related package object
*/
public function getPackage()
{
if ($this->package === null) {
$this->package = PackageCache::getInstance()->getPackage($this->packageID);
}
return $this->package;
}
/**
* Returns absolute page URL.
*
* @return string
*/
public function getPageURL()
{
if (empty($this->pageURL)) {
$this->pageURL = RouteHandler::getProtocol() . $this->domainName . $this->domainPath;
}
return $this->pageURL;
}
/**
* @inheritDoc
*/
public function __wakeup()
{
if (ENABLE_ENTERPRISE_MODE && \defined('ENTERPRISE_MODE_DOMAIN_OVERRIDE') && ENTERPRISE_MODE_DOMAIN_OVERRIDE === $_SERVER['HTTP_HOST']) {
$this->pageURL = '';
}
}
/**
* Returns the directory of the application with the given abbreviation.
*
* @param string $abbreviation
* @return string
* @throws SystemException
*/
public static function getDirectory($abbreviation)
{
if (static::$directories === null) {
static::$directories = [];
// read application directories
$packageList = new PackageList();
$packageList->getConditionBuilder()->add('package.isApplication = ?', [1]);
$packageList->readObjects();
foreach ($packageList as $package) {
$abbr = Package::getAbbreviation($package->package);
static::$directories[$abbr] = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir));
}
}
if (!isset(static::$directories[$abbreviation])) {
throw new SystemException("Unknown application '" . $abbreviation . "'");
}
return static::$directories[$abbreviation];
}
}