Fixed handling LESS overrides
authorAlexander Ebert <ebert@woltlab.com>
Mon, 29 Oct 2012 00:50:55 +0000 (01:50 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 29 Oct 2012 00:50:55 +0000 (01:50 +0100)
acptemplates/styleAdd.tpl
files/lib/acp/form/StyleAddForm.class.php
language/de.xml

index 5e198c08c6d4bbdae73d01e0c4c407a2bb6e0ab8..51ec3b67a7da30d0794b69c82a1b864181147236 100644 (file)
                                        <dd>
                                                <select name="wcfBaseFontFamily" id="wcfBaseFontFamily">
                                                        {foreach from=$availableFontFamilies key=fontFamily item=primaryFont}
-                                                               <option value="{@$fontFamily}"{if $variables[wcfBaseFontFamily] == $fontFamily} selected="selected"{/if}>{@$primaryFont}</option>
+                                                               <option value='{@$fontFamily}'{if $variables[wcfBaseFontFamily] == $fontFamily} selected="selected"{/if}>{@$primaryFont}</option>
                                                        {/foreach}
                                                </select>
                                        </dd>
                                <small>{lang}wcf.acp.style.advanced.individualLess.description{/lang}</small>
                        </fieldset>
                        
-                       <fieldset>
+                       <fieldset{if $errorField == 'overrideLess'} class="formError"{/if}>
                                <legend>{lang}wcf.acp.style.advanced.overrideLess{/lang}</legend>
                                
                                <p class="warning">{lang}wcf.acp.style.advanced.overrideLess.warning{/lang}</p>
                                
                                <textarea rows="20" cols="40" name="overrideLess" class="marginTop">{$variables[overrideLess]}</textarea>
+                               {if $errorField == 'overrideLess'}
+                                       <small class="innerError">
+                                               {lang}wcf.acp.style.advanced.overrideLess.error{/lang}
+                                               {implode from=$errorType item=error}{lang}wcf.acp.style.advanced.overrideLess.error.{$error.error}{/lang}{/implode}
+                                       </small>
+                               {/if}
                                <small>{lang}wcf.acp.style.advanced.overrideLess.description{/lang}</small>
                        </fieldset>
                </div>
index a9a7bc151b2fed7b359ece2dcf1c5618661a3fac..f0e595d3030a773ef30b695c7b91dce6234c24e8 100644 (file)
@@ -312,6 +312,7 @@ class StyleAddForm extends ACPForm {
                $sql = "SELECT  variableName
                        FROM    wcf".WCF_N."_style_variable";
                $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute();
                $variables = array();
                while ($row = $statement->fetchArray()) {
                        $variables[] = $row['variableName'];
@@ -319,6 +320,7 @@ class StyleAddForm extends ACPForm {
                
                $lines = explode("\n", StringUtil::unifyNewlines($this->variables['overrideLess']));
                $regEx = new Regex('^@([a-zA-Z]+): ?([@a-zA-Z0-9 ,\.\(\)\%]+);$');
+               $errors = array();
                foreach ($lines as $index => &$line) {
                        $line = StringUtil::trim($line);
                        
@@ -326,23 +328,37 @@ class StyleAddForm extends ACPForm {
                                $matches = $regEx->getMatches();
                                
                                // cannot override variables covered by style editor
-                               if (isset($this->variables[$matches[1]])) {
-                                       unset($lines[$index]);
+                               if (in_array($matches[1], $this->colors) || in_array($matches[1], $this->globals) || in_array($matches[1], $this->specialVariables)) {
+                                       $errors[] = array(
+                                               'error' => 'predefined',
+                                               'text' => $matches[1]
+                                       );
                                }
                                else if (!in_array($matches[1], $variables)) {
                                        // unknown style variable
-                                       unset($lines[$index]);
+                                       $errors[] = array(
+                                               'error' => 'unknown',
+                                               'text' => $matches[1]
+                                       );
                                }
                                else {
                                        $this->variables[$matches[1]] = $matches[2];
                                }
                        }
                        else {
-                               unset($lines[$index]);
+                               // not valid
+                               $errors[] = array(
+                                       'error' => 'notValid',
+                                       'text' => $line
+                               );
                        }
                }
                
                $this->variables['overrideLess'] = implode("\n", $lines);
+               
+               if (!empty($errors)) {
+                       throw new UserInputException('overrideLess', $errors);
+               }
        }
        
        /**
index 81089b273817001062331e5c025ce8dcc520d4ee..8184842144974a2254b65b5892cc01b191c905f0 100644 (file)
                <item name="wcf.acp.style.advanced.individualLess.description"><![CDATA[Die Eingabe wird am Ende des Stils eingefügt und kann vollständig aus CSS bestehen. Sie haben zusätzlich den Zugriff auf LESS und alle von Community Framework zur Verfügung gestellten Mixins.]]></item>
                <item name="wcf.acp.style.advanced.overrideLess"><![CDATA[Überschreiben von LESS-Variablen]]></item>
                <item name="wcf.acp.style.advanced.overrideLess.description"><![CDATA[Sie können innerhalb dieser Eingabe beliebige LESS-Variablen überschreiben, die nicht durch den Stil-Editor direkt bearbeitbar ist. Beim Bezug auf andere Variablen muss sichergestellt werden, dass diese in der Reihenfolge vorher definiert wurden. Die Syntax muss wie folgt lauten: &bdquo;@variableName: variableValue;&ldquo;]]></item>
+               <item name="wcf.acp.style.advanced.overrideLess.error"><![CDATA[Ihre Eingabe war ungültig, bitte überprüfen Sie die folgenden Einträge:]]></item>
+               <item name="wcf.acp.style.advanced.overrideLess.error.notValid"><![CDATA[Eingabe &bdquo;{$error[text]}&ldquo; ungültig]]></item>
+               <item name="wcf.acp.style.advanced.overrideLess.error.predefined"><![CDATA[Variable &bdquo;{$error[text]}&ldquo; wird bereits durch den Stil-Editor gesetzt]]></item>
+               <item name="wcf.acp.style.advanced.overrideLess.error.unknown"><![CDATA[Variable &bdquo;{$error[text]}&ldquo; unbekannt]]></item>
                <item name="wcf.acp.style.advanced.overrideLess.warning"><![CDATA[Fehlerhafte Eingaben führen dazu, dass der Stil nicht erzeugt werden kann. Überschreiben Sie LESS-Variablen nur, wenn Sie sich den Auswirkungen bewusst sind und eine Änderung anderweitig nicht möglich ist.]]></item>
                <item name="wcf.acp.style.advanced.syntax"><![CDATA[Sie können sowohl CSS als auch <a href="{@$__wcf->getPath()}acp/dereferrer.php?url=http://www.lesscss.org">LESS</a> verwenden. Bitte beachten Sie, dass der Stil nicht erzeugt werden kann, wenn der LESS-Code ungültig ist.]]></item>
                <item name="wcf.acp.style.authorName"><![CDATA[Autor]]></item>