/**
  * Writes the style-*.css file.
  */
 public function writeStyleFile()
 {
     // get variables
     $variables = $this->getVariables();
     // parse additional styles
     self::parseAdditionalStyles($variables);
     // get file handle
     require_once WCF_DIR . 'lib/system/io/File.class.php';
     $file = new File(WCF_DIR . 'style/style-' . $this->styleID . '.css', 'wb');
     // include static styles
     $staticStyles = glob(WCF_DIR . 'style/*.css');
     if ($staticStyles) {
         foreach ($staticStyles as $staticStyle) {
             if (!preg_match('/style-\\d+(?:-rtl)?\\.css/', $staticStyle)) {
                 $contents = file_get_contents($staticStyle);
                 $contents = StyleUtil::compressCSS($contents);
                 $file->write("/* static: " . basename($staticStyle) . " */\n");
                 $file->write(StringUtil::trim($contents) . "\n");
             }
         }
     }
     // get attributes
     $file->write("/* dynamic style attributes */\n");
     $sortedAttributes = array();
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_style_variable_to_attribute\n\t\t\tORDER BY\tvariableName, attributeName, cssSelector";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!empty($variables[$row['variableName']])) {
             if (!isset($sortedAttributes[$row['variableName']])) {
                 $sortedAttributes[$row['variableName']] = array();
             }
             if (!isset($sortedAttributes[$row['variableName']][$row['attributeName']])) {
                 $sortedAttributes[$row['variableName']][$row['attributeName']] = array();
             }
             $sortedAttributes[$row['variableName']][$row['attributeName']][] = $row['cssSelector'];
         }
     }
     foreach ($sortedAttributes as $variableName => $attributes) {
         foreach ($attributes as $attributeName => $cssSelectors) {
             $count = 0;
             // write selectors
             $css1Selectors = $css2Selectors = array();
             foreach ($cssSelectors as $cssSelector) {
                 if (empty($cssSelector)) {
                     $file->write("/* " . $variableName . " */\n");
                     $file->write(StyleUtil::compressCSS($variables[$variableName]));
                     $file->write("\n");
                 } else {
                     if (preg_match('/^[a-z0-9.#:_\\s-*]+$/i', $cssSelector)) {
                         $css1Selectors[] = $cssSelector;
                     } else {
                         $css2Selectors[] = $cssSelector;
                     }
                 }
             }
             if (count($css1Selectors)) {
                 $file->write(implode(',', $css1Selectors));
                 $file->write("{");
                 // write attribute
                 if (!empty($attributeName)) {
                     $file->write($attributeName . ":");
                 }
                 // write value
                 $file->write($variables[$variableName]);
                 $file->write("}\n");
             }
             if (count($css2Selectors)) {
                 $file->write(implode(',', $css2Selectors));
                 $file->write("{");
                 // write attribute
                 if (!empty($attributeName)) {
                     $file->write($attributeName . ":");
                 }
                 // write value
                 $file->write($variables[$variableName]);
                 $file->write("}\n");
             }
         }
     }
     // close file
     $file->close();
     @chmod(WCF_DIR . 'style/style-' . $this->styleID . '.css', 0777);
     $this->writeStyleFileRTL();
 }
 /**
  * Updates the acp style file.
  */
 public static function updateStyleFile()
 {
     // get file handle
     require_once WCF_DIR . 'lib/system/io/File.class.php';
     $file = new File(WCF_DIR . 'acp/style/style-ltr.css', 'wb');
     // include static styles
     $staticStyles = glob(WCF_DIR . 'style/*.css');
     if ($staticStyles) {
         foreach ($staticStyles as $staticStyle) {
             if (!preg_match('/style-\\d+(?:-rtl)?\\.css/', $staticStyle)) {
                 // get style
                 $contents = file_get_contents($staticStyle);
                 // compress style
                 $contents = StyleUtil::compressCSS($contents);
                 // fix icon/image path
                 $contents = str_replace('../icon/', '../../icon/', $contents);
                 $contents = str_replace('../images/', '../../images/', $contents);
                 // write style
                 $file->write("/* static: " . basename($staticStyle) . " */\n");
                 $file->write(StringUtil::trim($contents) . "\n");
             }
         }
     }
     // include static acp styles
     $staticStyles = glob(WCF_DIR . 'acp/style/*.css');
     if ($staticStyles) {
         foreach ($staticStyles as $staticStyle) {
             if (!preg_match('/style-(?:ltr|rtl)\\.css/', $staticStyle) && !preg_match('/ie\\dFix\\.css/', $staticStyle)) {
                 $contents = file_get_contents($staticStyle);
                 $contents = StyleUtil::compressCSS($contents);
                 $file->write("/* static: acp/" . basename($staticStyle) . " */\n");
                 $file->write(StringUtil::trim($contents) . "\n");
             }
         }
     }
     // close file
     $file->close();
     @chmod(WCF_DIR . 'acp/style/style-ltr.css', 0777);
     // update rtl version
     self::updateStyleFileRTL();
 }