Download Google Font in StyleAddForm
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 15 Jul 2020 09:28:31 +0000 (11:28 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 15 Jul 2020 10:17:33 +0000 (12:17 +0200)
see #3394

wcfsetup/install/files/acp/templates/styleAdd.tpl
wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index d848ffb46261ad29d93d50b09c58dd49d649257b..a4778a18c7b10c89cfe6e89f4552eec505c9a06c 100644 (file)
                                                <span>{lang}wcf.acp.style.globals.useGoogleFont{/lang}</span>
                                        </label></dd>
                                </dl>
-                               <dl id="wcfFontFamilyGoogleContainer">
+                               <dl id="wcfFontFamilyGoogleContainer"{if $errorField == 'wcfFontFamilyGoogle'} class="formError"{/if}>
                                        <dt><label for="wcfFontFamilyGoogle">{lang}wcf.acp.style.globals.fontFamilyGoogle{/lang}</label></dt>
                                        <dd>
                                                <input type="text" id="wcfFontFamilyGoogle" name="wcfFontFamilyGoogle" value="{$variables[wcfFontFamilyGoogle]}" class="medium">
+                                               <small>{lang}wcf.acp.style.globals.fontFamilyGoogle.description{/lang}</small>
+                                               {if $errorField == 'wcfFontFamilyGoogle'}
+                                                       <small class="innerError">
+                                                               {if $errorType == 'empty'}
+                                                                       {lang}wcf.global.form.error.empty{/lang}
+                                                               {else}
+                                                                       {lang}wcf.acp.style.globals.fontFamilyGoogle.error.{$errorType}{/lang}
+                                                               {/if}
+                                                       </small>
+                                               {/if}
                                        </dd>
                                </dl>
                                <dl>
index b26656fb43d772019370b615e8cb96b262cf0330..de23403372af297ef26a22294c077bc9e5570e1e 100644 (file)
@@ -11,6 +11,8 @@ use wcf\system\exception\SystemException;
 use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
 use wcf\system\Regex;
+use wcf\system\style\exception\FontDownloadFailed;
+use wcf\system\style\FontManager;
 use wcf\system\WCF;
 use wcf\util\ArrayUtil;
 use wcf\util\DateUtil;
@@ -293,6 +295,24 @@ class StyleAddForm extends AbstractForm {
                if (isset($_POST['scrollOffsets']) && is_array($_POST['scrollOffsets'])) $this->scrollOffsets = ArrayUtil::toIntegerArray($_POST['scrollOffsets']); 
        }
        
+       /**
+        * @since       5.3
+        */
+       protected function downloadGoogleFont() {
+               $fontManager = FontManager::getInstance();
+               $family = $this->variables['wcfFontFamilyGoogle'];
+               if ($family) {
+                       if (!$fontManager->isFamilyDownloaded($family)) {
+                               try {
+                                       $fontManager->downloadFamily($family);
+                               }
+                               catch (FontDownloadFailed $e) {
+                                       throw new UserInputException('wcfFontFamilyGoogle', 'downloadFailed'.($e->getReason() ? '.'.$e->getReason() : ''));
+                               }
+                       }
+               }
+       }
+       
        /**
         * @inheritDoc
         */
@@ -357,6 +377,8 @@ class StyleAddForm extends AbstractForm {
                }
                
                $this->validateApiVersion();
+               
+               $this->downloadGoogleFont();
        }
        
        /**
index c29fe1b70e49f3d52237cb704f7a5e0d25f049b8..7f735aabc84fc9f4daf5aec9c2b3c057d5d1fb4c 100644 (file)
@@ -2949,6 +2949,9 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen
                <item name="wcf.acp.style.globals.fontSizeTitle"><![CDATA[Schriftgröße (Seiten-Titel)]]></item>
                <item name="wcf.acp.style.globals.useGoogleFont"><![CDATA[Google-Schriftart aktivieren]]></item>
                <item name="wcf.acp.style.globals.fontFamilyGoogle"><![CDATA[Schriftart]]></item>
+               <item name="wcf.acp.style.globals.fontFamilyGoogle.description"><![CDATA[Die angegebene Schriftart wird beim Speichern des Stils heruntergeladen und anschließend den Benutzern anschließend ohne externe Verbindungen als Webfont zur Verfügung gestellt.]]></item>
+               <item name="wcf.acp.style.globals.fontFamilyGoogle.error.downloadFailed"><![CDATA[Der Download der Schriftart ist fehlgeschlagen.]]></item>
+               <item name="wcf.acp.style.globals.fontFamilyGoogle.error.downloadFailed.notFound"><![CDATA[Die angegebene Schriftart konnte nicht gefunden werden.]]></item>
                <item name="wcf.acp.style.globals.fontFamilyFallback"><![CDATA[Schriftart (Fallback)]]></item>
                <item name="wcf.acp.style.general.favicon"><![CDATA[Favicon]]></item>
                <item name="wcf.acp.style.favicon"><![CDATA[Individuelles Favicon]]></item>
index 6c7d81b8d8054392a588728383b1c9a53fde001e..00edddeb3bcb8662a382fd748e22bc3cd871b8de 100644 (file)
@@ -2877,6 +2877,9 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
                <item name="wcf.acp.style.globals.fontSizeTitle"><![CDATA[Font Size (Page Title)]]></item>
                <item name="wcf.acp.style.globals.useGoogleFont"><![CDATA[Use Google font face]]></item>
                <item name="wcf.acp.style.globals.fontFamilyGoogle"><![CDATA[Font Face]]></item>
+               <item name="wcf.acp.style.globals.fontFamilyGoogle.description"><![CDATA[The given font face will be downloaded when saving the style and afterwards will be delivered as a web font without connecting to external services.]]></item>
+               <item name="wcf.acp.style.globals.fontFamilyGoogle.error.downloadFailed"><![CDATA[Downloading the given font face failed.]]></item>
+               <item name="wcf.acp.style.globals.fontFamilyGoogle.error.downloadFailed.notFound"><![CDATA[The given font face could not be found.]]></item>
                <item name="wcf.acp.style.globals.fontFamilyFallback"><![CDATA[Font Face (Fallback)]]></item>
                <item name="wcf.acp.style.favicon"><![CDATA[Individual Favicon]]></item>
                <item name="wcf.acp.style.favicon.description"><![CDATA[Upload an 256×256 pixels image, acceptable image types are JPG and PNG. The uploaded image will be used to derive all required favicon sizes.]]></item>