Merge branch 'master' into style-cleanup
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 23 Jul 2020 12:09:59 +0000 (14:09 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 23 Jul 2020 12:09:59 +0000 (14:09 +0200)
1  2 
wcfsetup/install/files/acp/templates/styleAdd.tpl
wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php
wcfsetup/install/files/lib/data/style/StyleEditor.class.php

index 8fd207f570e5c9b35f83e22ca25b879a36aaf94c,fc5cea273a912b378430a2c363c6f4d46c6531e2..80b73c7e6ba0c1e1684bc2da363a603563cca124
@@@ -5,20 -5,38 +5,12 @@@
  {js application='wcf' acp='true' file='WCF.ACP.Style'}
  {js application='wcf' file='WCF.ColorPicker' bundle='WCF.Combined'}
  <script data-relocate="true">
--      require([
 -              'WoltLabSuite/Core/Acp/Ui/Style/CoverPhoto/Delete', 'WoltLabSuite/Core/Acp/Ui/Style/CoverPhoto/Upload', 'WoltLabSuite/Core/Acp/Ui/Style/Favicon/Upload', 'WoltLabSuite/Core/Acp/Ui/Style/Image/Upload',
--              'WoltLabSuite/Core/Acp/Ui/Style/Editor', 'WoltLabSuite/Core/Ui/Toggle/Input', 'Language'
--      ], function(
 -              AcpUiStyleCoverPhotoDelete, AcpUiStyleCoverPhotoUpload, AcpUiStyleFaviconUpload, AcpUiStyleImageUpload,
--              AcpUiStyleEditor, UiToggleInput, Language
--      ) {
++      require(['WoltLabSuite/Core/Acp/Ui/Style/Editor'], function(AcpUiStyleEditor) {
                AcpUiStyleEditor.setup({
                        isTainted: {if $isTainted}true{else}false{/if},
                        styleId: {if $action === 'edit'}{@$style->styleID}{else}0{/if},
                        styleRuleMap: styleRuleMap
                });
--              
-               new UiToggleInput('input[name="useGoogleFont"]', {
-                       show: ['#wcfFontFamilyGoogleContainer']
-               });
 -              new AcpUiStyleImageUpload({if $action == 'add'}0{else}{@$style->styleID}{/if}, '{$tmpHash}', false);
 -              new AcpUiStyleImageUpload({if $action == 'add'}0{else}{@$style->styleID}{/if}, '{$tmpHash}', true);
 -              
 -              {if $action === 'edit'}
 -                      new AcpUiStyleFaviconUpload({@$style->styleID});
 -                      
 -                      {if MODULE_USER_COVER_PHOTO}
 -                              Language.addObject({
 -                                      'wcf.acp.style.coverPhoto.delete.confirmMessage': '{lang}wcf.acp.style.coverPhoto.delete.confirmMessage{/lang}',
 -                                      'wcf.user.coverPhoto.upload.error.invalidExtension': '{lang}wcf.user.coverPhoto.upload.error.invalidExtension{/lang}',
 -                                      'wcf.user.coverPhoto.upload.error.minHeight': '{lang}wcf.user.coverPhoto.upload.error.minHeight{/lang}',
 -                                      'wcf.user.coverPhoto.upload.error.minWidth': '{lang}wcf.user.coverPhoto.upload.error.minWidth{/lang}',
 -                                      'wcf.user.coverPhoto.upload.error.uploadFailed': '{lang}wcf.user.coverPhoto.upload.error.uploadFailed{/lang}'
 -                              });
 -                              
 -                              AcpUiStyleCoverPhotoDelete.init({@$style->styleID});
 -                              new AcpUiStyleCoverPhotoUpload({@$style->styleID});
 -                      {/if}
 -              {/if}
        });
        
        $(function() {
index 0ae22848560cca8e80b333f95629a17767d76462,96488ae62d565703e180728167ba32d525667085..44609054b14fdab520f62bd9ce888eba4f0203f6
@@@ -10,11 -9,10 +10,13 @@@ use wcf\form\AbstractForm
  use wcf\system\event\EventHandler;
  use wcf\system\exception\SystemException;
  use wcf\system\exception\UserInputException;
 +use wcf\system\file\upload\UploadField;
 +use wcf\system\file\upload\UploadHandler;
 +use wcf\system\image\ImageHandler;
  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;
@@@ -322,21 -292,26 +323,39 @@@ class StyleAddForm extends AbstractFor
                
                // codemirror scroll offset
                if (isset($_POST['scrollOffsets']) && is_array($_POST['scrollOffsets'])) $this->scrollOffsets = ArrayUtil::toIntegerArray($_POST['scrollOffsets']); 
 +              
 +              $this->uploads = [];
 +              foreach (array_keys($this->getUploadFields()) as $field) {
 +                      $removedFiles = UploadHandler::getInstance()->getRemovedFiledByFieldId($field);
 +                      if (!empty($removedFiles)) {
 +                              $this->uploads[$field] = null;
 +                      }
 +                      
 +                      $files = UploadHandler::getInstance()->getFilesByFieldId($field);
 +                      if (!empty($files)) {
 +                              $this->uploads[$field] = $files[0];
 +                      }
 +              }
        }
        
+       /**
+        * @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
         */
                
                $this->validateApiVersion();
                
 +              $this->validateUploads();
++              
+               $this->downloadGoogleFont();
        }
        
        /**
                $this->specialVariables = [
                        'individualScss',
                        'overrideScss',
 -                      'pageLogo',
                        'pageLogoWidth',
                        'pageLogoHeight',
 -                      'pageLogoMobile',
                        'useFluidLayout',
-                       'useGoogleFont',
                        'wcfFontFamilyGoogle',
                        'wcfFontFamilyFallback'
                ];