Add SCSS validation for Style(Add|Edit)Form
authorjoshuaruesweg <ruesweg@woltlab.com>
Tue, 21 Jul 2020 11:39:27 +0000 (13:39 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Tue, 21 Jul 2020 11:39:27 +0000 (13:39 +0200)
wcfsetup/install/files/acp/templates/styleAdd.tpl
wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php
wcfsetup/install/files/lib/acp/form/StyleEditForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index d848ffb46261ad29d93d50b09c58dd49d649257b..7e9b96a75cad90b324b572994378990874669078 100644 (file)
                                
                                {* custom declarations *}
                                <div id="advanced-custom" class="tabMenuContent">
-                                       <section class="section">
+                                       <section class="section"{if $errorField == 'individualScss'} formError{/if}>
                                                <h2 class="sectionTitle">{lang}wcf.acp.style.advanced.individualScss{/lang}</h2>
                                                
                                                <dl class="wide">
                                                                </div>
                                                                <small>{lang}wcf.acp.style.advanced.individualScss.description{/lang}</small>
                                                        </dd>
+                                                       {if $errorField == 'individualScss'}
+                                                               <small class="innerError">
+                                                                       {lang}wcf.acp.style.advanced.individualScss.error{/lang}
+                                                               </small>
+                                                       {/if}
                                                </dl>
                                        </section>
                                        
                                <div id="advanced-original" class="tabMenuContent">
                        {/if}
                        
-                       <section class="section">
+                       <section class="section{if $errorField == 'individualScss' && $isTainted} formError{/if}">
                                <h2 class="sectionTitle">{lang}wcf.acp.style.advanced.individualScss{/lang}{if !$isTainted} ({lang}wcf.acp.style.protected.less{/lang}){/if}</h2>
                                
                                <dl class="wide">
                                                </div>
                                                <small>{lang}wcf.acp.style.advanced.individualScss.description{/lang}</small>
                                        </dd>
+                                       {if $errorField == 'individualScss' && $isTainted}
+                                               <small class="innerError">
+                                                       {lang}wcf.acp.style.advanced.individualScss.error{/lang}
+                                               </small>
+                                       {/if}
                                </dl>
                        </section>
                        
index b26656fb43d772019370b615e8cb96b262cf0330..25937ee8507dcafa90468aec707135694a386ba6 100644 (file)
@@ -11,6 +11,7 @@ use wcf\system\exception\SystemException;
 use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
 use wcf\system\Regex;
+use wcf\system\style\StyleCompiler;
 use wcf\system\WCF;
 use wcf\util\ArrayUtil;
 use wcf\util\DateUtil;
@@ -356,9 +357,28 @@ class StyleAddForm extends AbstractForm {
                        $this->parseOverrides();
                }
                
+               $this->validateIndividualScss();
+               
                $this->validateApiVersion();
        }
        
+       /**
+        * Validates the individual scss.
+        * @throws      UserInputException
+        * @since       5.3
+        */
+       public function validateIndividualScss() {
+               $variables = array_merge(StyleCompiler::getDefaultVariables(), $this->variables);
+               
+               $result = StyleCompiler::getInstance()->testStyle($this->apiVersion, $this->imagePath, $variables);
+               
+               if ($result !== true) {
+                       throw new UserInputException('individualScss', [
+                               'message' => $result,
+                       ]);
+               }
+       }
+       
        /**
         * Disallow the use of `com.woltlab.*` for package names to avoid accidental collisions.
         * 
index ddbf303cbb905c0e4a339ea71aa8c3c95eaa51cb..e855f5bdcc24d5789d60fa19686d4364cbb24201 100644 (file)
@@ -5,7 +5,10 @@ use wcf\data\style\StyleAction;
 use wcf\data\user\cover\photo\UserCoverPhoto;
 use wcf\form\AbstractForm;
 use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\SystemException;
+use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
+use wcf\system\style\StyleCompiler;
 use wcf\system\WCF;
 
 /**
@@ -58,6 +61,30 @@ class StyleEditForm extends StyleAddForm {
                }
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function validateIndividualScss() {
+               $variables = $this->variables;
+               if (!$this->style->isTainted) {
+                       $variables['individualScss'] = Style::joinLessVariables($variables['individualScss'], $variables['individualScssCustom']);
+                       $variables['overrideScss'] = Style::joinLessVariables($variables['overrideScss'], $variables['overrideScssCustom']);
+                       
+                       unset($variables['individualScssCustom']);
+                       unset($variables['overrideScssCustom']);
+               }
+               
+               $variables = array_merge(StyleCompiler::getDefaultVariables(), $variables);
+               
+               $result = StyleCompiler::getInstance()->testStyle($this->apiVersion, $this->imagePath, $variables);
+               
+               if ($result !== true) {
+                       throw new UserInputException('individualScss', [
+                               'message' => $result,
+                       ]);
+               }
+       }
+       
        /**
         * @inheritDoc
         */
index c29fe1b70e49f3d52237cb704f7a5e0d25f049b8..b99a93427be6d4e18b02afa46aacfe4f1e31da67 100644 (file)
@@ -2839,6 +2839,7 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen
                <item name="wcf.acp.style.advanced.overrideScss.error.invalid"><![CDATA[Eingabe „{$error[text]}“ ungültig]]></item>
                <item name="wcf.acp.style.advanced.overrideScss.error.predefined"><![CDATA[Variable „{$error[text]}“ wird bereits durch den Stil-Editor gesetzt]]></item>
                <item name="wcf.acp.style.advanced.overrideScss.error.unknown"><![CDATA[Variable „{$error[text]}“ unbekannt]]></item>
+               <item name="wcf.acp.style.advanced.individualScss.error"><![CDATA[Der SCSS-Code ist invalid: {$errorType.message}.]]></item>
                <item name="wcf.acp.style.apiVersion"><![CDATA[Kompatibilität mit WoltLab Suite in Version]]></item>
                <item name="wcf.acp.style.apiVersion.deprecated"><![CDATA[veraltet]]></item>
                <item name="wcf.acp.style.apiVersion.description"><![CDATA[Deaktiviert ausgewählte Stil-Verbesserungen, um die Kompatibilität mit Stilen für eine ältere Version von WoltLab Suite zu gewährleisten.]]></item>
index 6c7d81b8d8054392a588728383b1c9a53fde001e..218dabaef589231ea82458be0c4abf95fb683b66 100644 (file)
@@ -2766,6 +2766,7 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
                <item name="wcf.acp.style.advanced.overrideScss.error.invalid"><![CDATA[The input for “{$error[text]}” invalid.]]></item>
                <item name="wcf.acp.style.advanced.overrideScss.error.predefined"><![CDATA[The variable “{$error[text]}” is already defined by the style editor.]]></item>
                <item name="wcf.acp.style.advanced.overrideScss.error.unknown"><![CDATA[The variable “{$error[text]}” is not recognized.]]></item>
+               <item name="wcf.acp.style.advanced.individualScss.error"><![CDATA[The SCSS code is invalid: {$errorType.message}.]]></item>
                <item name="wcf.acp.style.apiVersion"><![CDATA[Enable Compatibility Mode with WoltLab Suite]]></item>
                <item name="wcf.acp.style.apiVersion.deprecated"><![CDATA[deprecated]]></item>
                <item name="wcf.acp.style.apiVersion.description"><![CDATA[Disables selected style improvements in order to maximize compatibility with styles for earlier versions of WoltLab Suite.]]></item>