Reworked the rewrite rule generator
authorAlexander Ebert <ebert@woltlab.com>
Thu, 25 Jul 2019 14:33:34 +0000 (16:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 25 Jul 2019 14:33:34 +0000 (16:33 +0200)
See #2903

wcfsetup/install/files/acp/templates/__optionRewriteRulesOutput.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/data/option/OptionAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

diff --git a/wcfsetup/install/files/acp/templates/__optionRewriteRulesOutput.tpl b/wcfsetup/install/files/acp/templates/__optionRewriteRulesOutput.tpl
new file mode 100644 (file)
index 0000000..38236b8
--- /dev/null
@@ -0,0 +1,13 @@
+{foreach from=$rewriteRules key=$webserver item=$rules}
+       <section class="section">
+               <h2 class="sectionTitle">{lang}wcf.acp.rewrite.{$webserver}{/lang}</h2>
+               
+               {foreach from=$rules key=$path item=content}
+                       <p>
+                               <span class="inlineCode">{$path}</span>
+                       </p>
+                       <pre>{$content}</pre>
+               {/foreach}
+       </section>
+{/foreach}
+
index bb4573661d364371d06ad23ba7b33362d5bb076c..d847b9cbe62c930a7b8831b48d72d081acacc37c 100644 (file)
@@ -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 .= <<<SNIPPET
-<span class="inlineCode">{$path}</span>
-<pre>{$content}</pre>
-<br>
-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 = <<<SNIPPET
+                               $htaccess = "{$dir}.htaccess";
+                               if (empty($rules['apache'][$htaccess])) {
+                                       $path = FileUtil::removeTrailingSlash(substr($value, strlen($dir)));
+                                       $rules['apache'][$htaccess] = <<<SNIPPET
 RewriteCond %{SCRIPT_FILENAME} !-d
 RewriteCond %{SCRIPT_FILENAME} !-f
 RewriteRule ^/{$path}(.*)$ {$path}/index.php?$1 [L,QSA]
 SNIPPET;
-                               $rules[$dir . '.htaccess'] = (!empty($rules[$dir . '.htaccess']) ? $rules[$dir . '.htaccess'] . "\n \n " : '') . $snippet;
+                               }
                        }
                }
                
index bb7733a34aef46d8a51e610c04aabcdeb388a0eb..b864735f1b25318d8ebbcf2ce4a4a064f76f1eeb 100644 (file)
@@ -2614,10 +2614,10 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen
                <item name="wcf.acp.rescueMode.username.notAuthorized"><![CDATA[Diese Benutzer ist nicht berechtigt die Konfiguration zu verändern.]]></item>
        </category>
        <category name="wcf.acp.rewrite">
-               <item name="wcf.acp.rewrite"><![CDATA[Rewrite-Regeln (Apache)]]></item>
+               <item name="wcf.acp.rewrite"><![CDATA[Rewrite-Regeln]]></item>
+               <item name="wcf.acp.rewrite.apache"><![CDATA[Apache (.htaccess)]]></item>
                <item name="wcf.acp.rewrite.generate"><![CDATA[Rewrite-Regeln generieren]]></item>
                <item name="wcf.acp.rewrite.description"><![CDATA[Generiert die Inhalte der benötigten .htaccess-Dateien und gibt sie aus. Beachte{if !LANGUAGE_USE_INFORMAL_VARIANT}n Sie{/if} bitte, dass die benötigten Regeln bei speziellen Server-Konfigurationen abweichen können.]]></item>
-               <item name="wcf.acp.rewrite.error.notApache"><![CDATA[Der Webserver konnte nicht als Apache identifiziert werden. Diese Funktion unterstützt ausschließlich Rewrite-Regeln für Apache.]]></item>
        </category>
        <category name="wcf.acp.search">
                <item name="wcf.acp.search.noResults"><![CDATA[Keine Treffer]]></item>
index 231c2d4597308315fc625052757a48423bc803b4..5461a5e019267c74bde325365b891df17aa23064 100644 (file)
@@ -2542,10 +2542,10 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
                <item name="wcf.acp.rescueMode.username.notAuthorized"><![CDATA[This user is not authorized to manage installed apps.]]></item>
        </category>
        <category name="wcf.acp.rewrite">
-               <item name="wcf.acp.rewrite"><![CDATA[Rewrite Rules (Apache)]]></item>
+               <item name="wcf.acp.rewrite"><![CDATA[Rewrite Rules]]></item>
+               <item name="wcf.acp.rewrite.apache"><![CDATA[Apache (.htaccess)]]></item>
                <item name="wcf.acp.rewrite.generate"><![CDATA[Generate Rewrite-Rules]]></item>
                <item name="wcf.acp.rewrite.description"><![CDATA[Generates the rewrite rules for necessary .htaccess-files. Please keep in mind, that you might have to provide different rules for special webserver configurations.]]></item>
-               <item name="wcf.acp.rewrite.error.notApache"><![CDATA[Your webserver could not be identified as Apache. This function supports rewrite rules for Apache only.]]></item>
        </category>
        <category name="wcf.acp.search">
                <item name="wcf.acp.search.noResults"><![CDATA[No results]]></item>