From b6ee3a6f3e324b5d4af012976a73203869652f01 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 25 Jul 2019 16:33:34 +0200 Subject: [PATCH] Reworked the rewrite rule generator See #2903 --- .../templates/__optionRewriteRulesOutput.tpl | 13 +++++++ .../lib/data/option/OptionAction.class.php | 38 +++++++------------ wcfsetup/install/lang/de.xml | 4 +- wcfsetup/install/lang/en.xml | 4 +- 4 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 wcfsetup/install/files/acp/templates/__optionRewriteRulesOutput.tpl diff --git a/wcfsetup/install/files/acp/templates/__optionRewriteRulesOutput.tpl b/wcfsetup/install/files/acp/templates/__optionRewriteRulesOutput.tpl new file mode 100644 index 0000000000..38236b8464 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/__optionRewriteRulesOutput.tpl @@ -0,0 +1,13 @@ +{foreach from=$rewriteRules key=$webserver item=$rules} +
+

{lang}wcf.acp.rewrite.{$webserver}{/lang}

+ + {foreach from=$rules key=$path item=content} +

+ {$path} +

+
{$content}
+ {/foreach} +
+{/foreach} + diff --git a/wcfsetup/install/files/lib/data/option/OptionAction.class.php b/wcfsetup/install/files/lib/data/option/OptionAction.class.php index bb4573661d..d847b9cbe6 100644 --- a/wcfsetup/install/files/lib/data/option/OptionAction.class.php +++ b/wcfsetup/install/files/lib/data/option/OptionAction.class.php @@ -115,16 +115,8 @@ class OptionAction extends AbstractDatabaseObjectAction { return ['validationResult' => $smtp->testConnection()]; } - /** - * Validates the "generateRewriteRules" action - * @throws \wcf\system\exception\AJAXException - */ public function validateGenerateRewriteRules() { WCF::getSession()->checkPermissions(['admin.configuration.canEditOption']); - - if (!FileUtil::isApacheModule()) { - throw new AJAXException(WCF::getLanguage()->get('wcf.acp.rewrite.error.notApache')); - } } /** @@ -134,28 +126,22 @@ class OptionAction extends AbstractDatabaseObjectAction { * @return string */ public function generateRewriteRules() { - $output = ''; - - foreach ($this->fetchRewriteRules() as $path => $content) { - $output .= <<{$path} -
{$content}
-
-SNIPPET; - - } - - return $output; + return WCF::getTPL()->fetch('__optionRewriteRulesOutput', 'wcf', [ + 'rewriteRules' => $this->fetchRewriteRules(), + ]); } /** * Returns an array with rewrite rules per necessary directory/file * Applications in sub-directories of another application will be mapped to the top one * - * @return string[] + * @return string[][] */ protected function fetchRewriteRules() { - $dirs = $rules = []; + $dirs = []; + $rules = [ + 'apache' => [], + ]; foreach (ApplicationHandler::getInstance()->getApplications() as $app) { $test = $app->getPackage()->getAbsolutePackageDir(); $insert = true; @@ -187,13 +173,15 @@ SNIPPET; krsort($domainPaths); foreach ($domainPaths as $domainPath => $value) { - $path = FileUtil::removeTrailingSlash(substr($value, strlen($dir))); - $snippet = << - + + - diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 231c2d4597..5461a5e019 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2542,10 +2542,10 @@ If you have already bought the licenses for the listed apps, th - + + - -- 2.20.1