Allow applications to inject ACP SCSS stylesheets
authorAlexander Ebert <ebert@woltlab.com>
Wed, 28 Jun 2017 11:29:15 +0000 (13:29 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 28 Jun 2017 11:29:15 +0000 (13:29 +0200)
wcfsetup/install/files/lib/system/style/StyleCompiler.class.php

index 342f72ac39297ba0a6b06b80957f5c23f9c136c7..bd584a451b172de1907cabada5ed79f04a0b5d8c 100644 (file)
@@ -4,6 +4,7 @@ use Leafo\ScssPhp\Compiler;
 use wcf\data\application\Application;
 use wcf\data\option\Option;
 use wcf\data\style\Style;
+use wcf\system\application\ApplicationHandler;
 use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
 use wcf\system\SingletonFactory;
@@ -120,6 +121,13 @@ class StyleCompiler extends SingletonFactory {
                // ACP uses a slightly different layout
                $files[] = WCF_DIR . 'acp/style/layout.scss';
                
+               // include stylesheets from other apps in arbitrary order
+               if (PACKAGE_ID) {
+                       foreach (ApplicationHandler::getInstance()->getApplications() as $application) {
+                               $files = array_merge($files, $this->getAcpStylesheets($application));
+                       }
+               }
+               
                // read default values
                $sql = "SELECT          variableName, defaultValue
                        FROM            wcf".WCF_N."_style_variable
@@ -194,6 +202,25 @@ class StyleCompiler extends SingletonFactory {
                return $files;
        }
        
+       /**
+        * Returns the list of SCSS stylesheets of an application.
+        * 
+        * @param       Application     $application
+        * @return      string[]
+        */
+       protected function getAcpStylesheets(Application $application) {
+               if ($application->packageID == 1) return [];
+               
+               $files = [];
+               
+               $basePath = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $application->getPackage()->packageDir)) . 'acp/style/';
+               foreach (glob($basePath . '*.scss') as $file) {
+                       $files[] = $file;
+               }
+               
+               return $files;
+       }
+       
        /**
         * Prepares the style compiler by adding variables to environment.
         *