3 namespace wcf\data\option
;
5 use wcf\data\AbstractDatabaseObjectAction
;
6 use wcf\system\application\ApplicationHandler
;
7 use wcf\system\email\transport\SmtpEmailTransport
;
8 use wcf\system\exception\UserInputException
;
10 use wcf\util\FileUtil
;
13 * Executes option-related actions.
15 * @author Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\Data\Option
20 * @method Option create()
21 * @method OptionEditor[] getObjects()
22 * @method OptionEditor getSingleObject()
24 class OptionAction
extends AbstractDatabaseObjectAction
29 protected $className = OptionEditor
::class;
34 protected $permissionsCreate = ['admin.configuration.canEditOption'];
39 protected $permissionsDelete = ['admin.configuration.canEditOption'];
44 protected $permissionsUpdate = ['admin.configuration.canEditOption'];
49 protected $requireACP = [
56 'generateRewriteRules',
60 * Validates permissions and parameters.
62 public function validateImport()
64 parent
::validateCreate();
68 * Validates permissions and parameters.
70 public function validateUpdateAll()
72 parent
::validateCreate();
78 public function import()
81 \
call_user_func([$this->className
, 'import'], $this->parameters
['data']);
85 * Updates the value of all given options.
87 public function updateAll()
90 \
call_user_func([$this->className
, 'updateAll'], $this->parameters
['data']);
94 * Validates the basic SMTP connection parameters.
96 * @throws UserInputException
98 public function validateEmailSmtpTest()
100 WCF
::getSession()->checkPermissions($this->permissionsUpdate
);
102 $this->readString('host');
103 $this->readInteger('port');
104 $this->readString('startTls');
106 $this->readString('user', true);
107 $this->readString('password', true);
108 if (!empty($this->parameters
['user']) && empty($this->parameters
['password'])) {
109 throw new UserInputException('password');
110 } elseif (empty($this->parameters
['user']) && !empty($this->parameters
['password'])) {
111 throw new UserInputException('user');
116 * Runs a simple test of the SMTP connection.
120 public function emailSmtpTest()
122 $smtp = new SmtpEmailTransport(
123 $this->parameters
['host'],
124 $this->parameters
['port'],
125 $this->parameters
['user'],
126 $this->parameters
['password'],
127 $this->parameters
['startTls']
130 return ['validationResult' => $smtp->testConnection()];
133 public function validateGenerateRewriteRules()
135 WCF
::getSession()->checkPermissions(['admin.configuration.canEditOption']);
139 * Returns a list of code-bbcode-containers containing the necessary
144 public function generateRewriteRules()
146 return WCF
::getTPL()->fetch('__optionRewriteRulesOutput', 'wcf', [
147 'rewriteRules' => $this->fetchRewriteRules(),
152 * Returns an array with rewrite rules per necessary directory/file
153 * Applications in sub-directories of another application will be mapped to the top one
157 protected function fetchRewriteRules()
163 foreach (ApplicationHandler
::getInstance()->getApplications() as $app) {
164 $test = $app->getPackage()->getAbsolutePackageDir();
167 foreach ($dirs as $dir => $apps) {
168 if (\
strpos($dir, $test) !== false) {
170 } elseif (\
strpos($test, $dir) !== false) {
181 foreach (ApplicationHandler
::getInstance()->getApplications() as $application) {
182 foreach ($dirs as $dir => $value) {
183 if (\
strpos($application->getPackage()->getAbsolutePackageDir(), $dir) !== false) {
184 $dirs[$dir][$application->domainPath
] = $application->getPackage()->getAbsolutePackageDir();
189 foreach ($dirs as $dir => $domainPaths) {
190 \
krsort($domainPaths);
192 foreach ($domainPaths as $domainPath => $value) {
193 $htaccess = "{$dir}.htaccess";
194 $path = FileUtil
::addTrailingSlash(\
substr($value, \
strlen($dir)));
198 $content = <<<SNIPPET
199 RewriteCond %{SCRIPT_FILENAME} !-d
200 RewriteCond %{SCRIPT_FILENAME} !-f
201 RewriteRule ^{$path}(.*)$ {$path}index.php?$1 [L,QSA]
205 if (empty($rules['apache'][$htaccess])) {
206 $rules['apache'][$htaccess] = "RewriteEngine On\n\n{$content}";
208 $rules['apache'][$htaccess] .= $content;