3 namespace wcf\acp\form
;
5 use wcf\data\application\ViewableApplicationList
;
6 use wcf\data\page\Page
;
7 use wcf\data\page\PageList
;
8 use wcf\data\page\PageNodeTree
;
9 use wcf\form\AbstractForm
;
10 use wcf\system\application\ApplicationHandler
;
11 use wcf\system\cache\builder\ApplicationCacheBuilder
;
12 use wcf\system\cache\builder\PageCacheBuilder
;
13 use wcf\system\cache\builder\RoutingCacheBuilder
;
14 use wcf\system\exception\UserInputException
;
16 use wcf\system\style\StyleHandler
;
18 use wcf\util\ArrayUtil
;
19 use wcf\util\FileUtil
;
20 use wcf\util\StringUtil
;
23 * Shows the application management form.
25 * @author Alexander Ebert
26 * @copyright 2001-2021 WoltLab GmbH
27 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
29 final class ApplicationManagementForm
extends AbstractForm
34 public $activeMenuItem = 'wcf.acp.menu.link.application.management';
37 * list of applications
38 * @var ViewableApplicationList
40 public $applicationList;
45 public $cookieDomain = '';
50 public $domainName = '';
55 public $landingPageID = [];
60 public $neededPermissions = ['admin.configuration.canManageApplication'];
63 * nested list of page nodes
64 * @var \RecursiveIteratorIterator
71 public function readParameters()
73 parent
::readParameters();
75 $this->pageNodeList
= (new PageNodeTree())->getNodeList();
81 public function readFormParameters()
83 parent
::readFormParameters();
85 if (!ENABLE_ENTERPRISE_MODE || WCF
::getUser()->hasOwnerAccess()) {
86 if (isset($_POST['cookieDomain'])) {
87 $this->cookieDomain
= StringUtil
::trim($_POST['cookieDomain']);
89 if (isset($_POST['domainName'])) {
90 $this->domainName
= StringUtil
::trim($_POST['domainName']);
94 if (isset($_POST['landingPageID']) && \
is_array($_POST['landingPageID'])) {
95 $this->landingPageID
= ArrayUtil
::toIntegerArray($_POST['landingPageID']);
99 public function validate()
103 if (!ENABLE_ENTERPRISE_MODE || WCF
::getUser()->hasOwnerAccess()) {
104 if (empty($this->domainName
)) {
105 throw new UserInputException('domainName');
108 $regex = new Regex('^https?\://');
109 $this->domainName
= FileUtil
::removeTrailingSlash($regex->replace($this->domainName
, ''));
110 $this->cookieDomain
= FileUtil
::removeTrailingSlash($regex->replace($this->cookieDomain
, ''));
112 // domain may not contain path components
113 $regex = new Regex('[/#\?&]');
114 if ($regex->match($this->domainName
)) {
115 throw new UserInputException('domainName', 'containsPath');
116 } elseif ($regex->match($this->cookieDomain
)) {
117 throw new UserInputException('cookieDomain', 'containsPath');
120 // strip port from cookie domain
121 $regex = new Regex(':[0-9]+$');
122 $this->cookieDomain
= $regex->replace($this->cookieDomain
, '');
124 // check if cookie domain shares the same domain (may exclude subdomains)
125 if (!\
str_ends_with($regex->replace($this->domainName
, ''), $this->cookieDomain
)) {
126 throw new UserInputException('cookieDomain', 'invalid');
130 foreach ($this->landingPageID
as $landingPageID) {
131 if (!$landingPageID) {
135 $page = new Page($landingPageID);
136 if (!$page->pageID
) {
137 throw new UserInputException('landingPageID');
138 } elseif ($page->requireObjectID ||
$page->excludeFromLandingPage ||
$page->isDisabled
) {
139 throw new UserInputException('landingPageID', 'invalid');
147 public function readData()
151 $this->applicationList
= new ViewableApplicationList();
152 $this->applicationList
->readObjects();
154 $core = ApplicationHandler
::getInstance()->getApplicationByID(1);
155 $this->domainName
= $core->domainName
;
156 $this->cookieDomain
= $core->cookieDomain
;
159 public function save()
163 if (!ENABLE_ENTERPRISE_MODE || WCF
::getUser()->hasOwnerAccess()) {
164 $sql = "UPDATE wcf" . WCF_N
. "_application
167 $statement = WCF
::getDB()->prepareStatement($sql);
168 $statement->execute([
174 $sql = "UPDATE wcf" . WCF_N
. "_application
175 SET landingPageID = ?
176 WHERE packageID = ?";
177 $statement = WCF
::getDB()->prepareStatement($sql);
178 foreach ($this->landingPageID
as $packageID => $landingPageID) {
179 $statement->execute([
180 $landingPageID ?
: null,
187 ApplicationHandler
::rebuild();
189 // Reset caches to reflect the new landing pages.
190 ApplicationCacheBuilder
::getInstance()->reset();
191 PageCacheBuilder
::getInstance()->reset();
192 RoutingCacheBuilder
::getInstance()->reset();
193 StyleHandler
::resetStylesheets();
195 // Reload the applications to update the selected landing page id.
196 $this->applicationList
= new ViewableApplicationList();
197 $this->applicationList
->readObjects();
199 // show success message
200 WCF
::getTPL()->assign('success', true);
206 public function assignVariables()
208 parent
::assignVariables();
210 $pageList = new PageList();
211 $pageList->readObjects();
213 WCF
::getTPL()->assign([
214 'applicationList' => $this->applicationList
,
215 'cookieDomain' => $this->cookieDomain
,
216 'domainName' => $this->domainName
,
217 'pageNodeList' => $this->pageNodeList
,
218 'pageList' => $pageList->getObjects(),