Added global (S)CSS input
authorAlexander Ebert <ebert@woltlab.com>
Thu, 2 Nov 2017 12:45:15 +0000 (13:45 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 2 Nov 2017 12:45:15 +0000 (13:45 +0100)
Closes #2466

com.woltlab.wcf/acpMenu.xml
wcfsetup/install/files/acp/templates/styleGlobalValues.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/acp/form/StyleGlobalValuesForm.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/style/StyleCompiler.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index bf924d82f699a4486cea5793df0aacaf782bcd30..6f6cce24ff25a0b00fe87c10e712b70895554b40 100644 (file)
                                <permissions>admin.style.canManageStyle</permissions>
                                <icon>fa-plus</icon>
                        </acpmenuitem>
+                               
+                       <acpmenuitem name="wcf.acp.menu.link.style.globalValues">
+                               <controller>wcf\acp\form\StyleGlobalValuesForm</controller>
+                               <parent>wcf.acp.menu.link.style</parent>
+                               <permissions>admin.style.canManageStyle</permissions>
+                       </acpmenuitem>
                        <!-- /style -->
                        
                        <!-- template -->
diff --git a/wcfsetup/install/files/acp/templates/styleGlobalValues.tpl b/wcfsetup/install/files/acp/templates/styleGlobalValues.tpl
new file mode 100644 (file)
index 0000000..0408d87
--- /dev/null
@@ -0,0 +1,45 @@
+{include file='header' pageTitle='wcf.acp.style.globalValues'}
+
+<header class="contentHeader">
+       <div class="contentHeaderTitle">
+               <h1 class="contentTitle">{lang}wcf.acp.style.globalValues{/lang}</h1>
+               <p class="contentHeaderDescription">{lang}wcf.acp.style.globalValues.description{/lang}</p>
+       </div>
+       
+       <nav class="contentHeaderNavigation">
+               <ul>
+                       <li><a href="{link controller='StyleList'}{/link}" class="button"><span class="icon icon16 fa-list"></span> <span>{lang}wcf.acp.menu.link.style.list{/lang}</span></a></li>
+                       
+                       {event name='contentHeaderNavigation'}
+               </ul>
+       </nav>
+</header>
+
+{include file='formError'}
+
+{if $success|isset}
+       <p class="success">{lang}wcf.global.success{/lang}</p>
+{/if}
+
+<form method="post" action="{link controller='StyleGlobalValues'}{/link}">
+       <div class="section">
+               <dl>
+                       <dt>{lang}wcf.acp.style.globalValues.input{/lang}</dt>
+                       <dd>
+                               <div dir="ltr">
+                                       <textarea id="styles" rows="20" cols="40" name="styles" style="visibility: hidden">{$styles}</textarea>
+                               </div>
+                       </dd>
+               </dl>
+               {include file='codemirror' codemirrorMode='text/x-less' codemirrorSelector='#styles'}
+       </div>
+       
+       {event name='sections'}
+       
+       <div class="formSubmit">
+               <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
+               {@SECURITY_TOKEN_INPUT_TAG}
+       </div>
+</form>
+
+{include file='footer'}
diff --git a/wcfsetup/install/files/lib/acp/form/StyleGlobalValuesForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleGlobalValuesForm.class.php
new file mode 100644 (file)
index 0000000..a574493
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+namespace wcf\acp\form;
+use wcf\form\AbstractForm;
+use wcf\system\style\StyleCompiler;
+use wcf\system\style\StyleHandler;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
+
+/**
+ * Shows the form input for global style values.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\Acp\Form
+ */
+class StyleGlobalValuesForm extends AbstractForm {
+       /**
+        * @inheritDoc
+        */
+       public $activeMenuItem = 'wcf.acp.menu.link.style.globalValues';
+       
+       /**
+        * global SCSS styles
+        * @var string
+        */
+       public $styles = '';
+       
+       /**
+        * @inheritDoc
+        */
+       public function readFormParameters() {
+               parent::readFormParameters();
+               
+               if (isset($_POST['styles'])) {
+                       $this->styles = StringUtil::unifyNewlines(StringUtil::trim($_POST['styles']));
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function readData() {
+               parent::readData();
+               
+               if (file_exists(WCF_DIR . StyleCompiler::FILE_GLOBAL_VALUES)) {
+                       $this->styles = file_get_contents(WCF_DIR . StyleCompiler::FILE_GLOBAL_VALUES);
+                       // strip the first line which will always contain a comment
+                       $this->styles = explode("\n", $this->styles, 2)[1];
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function save() {
+               parent::save();
+               
+               if (empty($this->styles)) {
+                       if (file_exists(WCF_DIR . StyleCompiler::FILE_GLOBAL_VALUES)) {
+                               unlink(WCF_DIR . StyleCompiler::FILE_GLOBAL_VALUES);
+                       }
+               }
+               else {
+                       file_put_contents(WCF_DIR . StyleCompiler::FILE_GLOBAL_VALUES, "/* DO NOT EDIT THIS FILE -- Dynamic global SCSS values, generated at ".date('r', TIME_NOW)." */\n" . $this->styles);
+               }
+               
+               // call saved event
+               $this->saved();
+               
+               // reset stylesheets
+               StyleHandler::resetStylesheets(false);
+               
+               WCF::getTPL()->assign('success', true);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function assignVariables() {
+               parent::assignVariables();
+               
+               WCF::getTPL()->assign([
+                       'styles' => $this->styles
+               ]);
+       }
+}
index fa16b6cc4c8876f4200afc7af6cf59e53511f21c..81ca3354a8e49040813c361254b8d3cc8a4e9f78 100644 (file)
@@ -34,6 +34,12 @@ class StyleCompiler extends SingletonFactory {
         */
        public static $supportedOptionType = ['boolean', 'integer'];
        
+       /**
+        * file used to store global SCSS declarations, relative to `WCF_DIR`
+        * @var string
+        */
+       const FILE_GLOBAL_VALUES = 'style/ui/zzz_wsc_style_global_values.scss';
+       
        /**
         * @inheritDoc
         */
@@ -63,9 +69,19 @@ class StyleCompiler extends SingletonFactory {
                        1
                ]);
                while ($row = $statement->fetchArray()) {
+                       // the global values will always be evaluated last
+                       if ($row['filename'] === self::FILE_GLOBAL_VALUES) {
+                               continue;
+                       }
+                       
                        $files[] = Application::getDirectory($row['application']).$row['filename'];
                }
                
+               // global SCSS
+               if (file_exists(WCF_DIR . self::FILE_GLOBAL_VALUES)) {
+                       $files[] = WCF_DIR . self::FILE_GLOBAL_VALUES;
+               }
+               
                // get style variables
                $variables = $style->getVariables();
                $individualScss = '';
index dd7d48e6256785ed9fd7286c64e230815d38c8e9..a91a836b9cdb5017963c4fc53cde545a7fdc3c31 100644 (file)
                <item name="wcf.acp.menu.link.package.list"><![CDATA[Pakete]]></item>
                <item name="wcf.acp.menu.link.style"><![CDATA[Stile]]></item>
                <item name="wcf.acp.menu.link.style.add"><![CDATA[Stil hinzufügen]]></item>
+               <item name="wcf.acp.menu.link.style.globalValues"><![CDATA[Stilunabhängiges CSS und SCSS]]></item>
                <item name="wcf.acp.menu.link.style.import"><![CDATA[Stil importieren]]></item>
                <item name="wcf.acp.menu.link.style.list"><![CDATA[Stile]]></item>
                <item name="wcf.acp.menu.link.configuration"><![CDATA[Konfiguration]]></item>
@@ -1945,6 +1946,9 @@ Als Benachrichtigungs-URL in der Konfiguration der sofortigen Zahlungsbestätigu
                <item name="wcf.acp.style.globals.fontSize"><![CDATA[Schriftgröße]]></item>
                <item name="wcf.acp.style.globals.layout"><![CDATA[Layout]]></item>
                <item name="wcf.acp.style.globals.useFluidLayout"><![CDATA[Flexible Breite verwenden]]></item>
+               <item name="wcf.acp.style.globalValues"><![CDATA[Stilunabhängiges CSS und SCSS]]></item>
+               <item name="wcf.acp.style.globalValues.description"><![CDATA[Das unten stehende CSS und SCSS wird auf alle Stile angewandt, die individuelle Anpassungen in den Stilen sind jedoch höherwertig.]]></item>
+               <item name="wcf.acp.style.globalValues.input"><![CDATA[Individuelles CSS und SCSS]]></item>
                <item name="wcf.acp.style.image"><![CDATA[Vorschaubild]]></item>
                <item name="wcf.acp.style.image.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Lade{else}Laden Sie{/if} hier ein Vorschaubild dieses Stiles hoch, als Bildformate sind JPG und PNG zulässig. Es wird empfohlen Vorschaubilder immer mit der Größe 102px × 64px anzulegen, größere Grafiken werden automatisch skaliert.]]></item>
                <item name="wcf.acp.style.image2x"><![CDATA[Vorschaubild (HD)]]></item>
index f3a261fac358fe7a7e0491e64c98bbcc334654d3..74d6f6dca9c51686aff7f7653accd52c4aa38feb 100644 (file)
                <item name="wcf.acp.menu.link.package.list"><![CDATA[Packages]]></item>
                <item name="wcf.acp.menu.link.style"><![CDATA[Styles]]></item>
                <item name="wcf.acp.menu.link.style.add"><![CDATA[Add Style]]></item>
+               <item name="wcf.acp.menu.link.style.globalValues"><![CDATA[Global CSS and SCSS]]></item>
                <item name="wcf.acp.menu.link.style.import"><![CDATA[Import Style]]></item>
                <item name="wcf.acp.menu.link.style.list"><![CDATA[Styles]]></item>
                <item name="wcf.acp.menu.link.configuration"><![CDATA[Configuration]]></item>
@@ -1888,6 +1889,9 @@ When prompted for the notification URL for the instant payment notifications, pl
                <item name="wcf.acp.style.globals.fontSize"><![CDATA[Font Size]]></item>
                <item name="wcf.acp.style.globals.layout"><![CDATA[Layout]]></item>
                <item name="wcf.acp.style.globals.useFluidLayout"><![CDATA[Use fluid width]]></item>
+               <item name="wcf.acp.style.globalValues"><![CDATA[Global CSS and SCSS]]></item>
+               <item name="wcf.acp.style.globalValues.description"><![CDATA[The CSS and SCSS entered below is applied to all styles, but custom values in styles take precedence.]]></item>
+               <item name="wcf.acp.style.globalValues.input"><![CDATA[Individual CSS and SCSS]]></item>
                <item name="wcf.acp.style.image"><![CDATA[Preview Image]]></item>
                <item name="wcf.acp.style.image.description"><![CDATA[Upload a preview image for this style, acceptable image types are JPG and PNG. Dimensions should be 102px × 64px, exceeding images will be scaled.]]></item>
                <item name="wcf.acp.style.image2x"><![CDATA[Preview Image (HD)]]></item>