Пример #1
0
 /**
  * Compiles LESS stylesheets into one CSS-stylesheet and writes them
  * to filesystem. Please be aware not to append '.css' within $filename!
  * 
  * @param	string			$filename
  * @param	array<string>		$files
  * @param	array<string>		$variables
  * @param	string			$individualLess
  * @param	\wcf\system\Callback	$callback
  */
 protected function compileStylesheet($filename, array $files, array $variables, $individualLess, Callback $callback)
 {
     foreach ($variables as &$value) {
         if (StringUtil::startsWith($value, '../')) {
             $value = '~"' . $value . '"';
         }
     }
     unset($value);
     // add options as LESS variables
     if (PACKAGE_ID) {
         foreach (Option::getOptions() as $constantName => $option) {
             if (in_array($option->optionType, static::$supportedOptionType)) {
                 $variables['wcf_option_' . mb_strtolower($constantName)] = '~"' . $option->optionValue . '"';
             }
         }
     } else {
         // workaround during setup
         $variables['wcf_option_attachment_thumbnail_height'] = '~"210"';
         $variables['wcf_option_attachment_thumbnail_width'] = '~"280"';
         $variables['wcf_option_signature_max_image_height'] = '~"150"';
     }
     // build LESS bootstrap
     $less = $this->bootstrap($variables);
     foreach ($files as $file) {
         $less .= $this->prepareFile($file);
     }
     // append individual CSS/LESS
     if ($individualLess) {
         $less .= $individualLess;
     }
     try {
         $content = $this->compiler->compile($less);
     } catch (\Exception $e) {
         throw new SystemException("Could not compile LESS: " . $e->getMessage(), 0, '', $e);
     }
     $content = $callback($content);
     // compress stylesheet
     $lines = explode("\n", $content);
     $content = $lines[0] . "\n" . $lines[1] . "\n";
     for ($i = 2, $length = count($lines); $i < $length; $i++) {
         $line = trim($lines[$i]);
         $content .= $line;
         switch (substr($line, -1)) {
             case ',':
                 $content .= ' ';
                 break;
             case '}':
                 $content .= "\n";
                 break;
         }
         if (substr($line, 0, 6) == '@media') {
             $content .= "\n";
         }
     }
     // write stylesheet
     file_put_contents($filename . '.css', $content);
     FileUtil::makeWritable($filename . '.css');
     // convert stylesheet to RTL
     $content = StyleUtil::convertCSSToRTL($content);
     // write stylesheet for RTL
     file_put_contents($filename . '-rtl.css', $content);
     FileUtil::makeWritable($filename . '-rtl.css');
 }
Пример #2
0
 /**
  * Compiles LESS stylesheets.
  * 
  * @param	\cms\data\stylesheet\Stylesheet		$stylesheet
  * @param	integer					$styleID
  */
 public function compile(Stylesheet $stylesheet, $styleID = null)
 {
     $styles = StyleHandler::getInstance()->getStyles();
     // compile stylesheet for all installed styles
     if ($styleID === null) {
         foreach ($styles as $style) {
             $this->compile($stylesheet, $style->styleID);
         }
         return;
     }
     $style = $styles[$styleID];
     // get style variables
     $variables = $style->getVariables();
     if (isset($variables['individualLess'])) {
         unset($variables['individualLess']);
     }
     // add style image path
     $imagePath = '../images/';
     if ($style->imagePath) {
         $imagePath = FileUtil::getRelativePath(WCF_DIR . 'style/', WCF_DIR . $style->imagePath);
         $imagePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator($imagePath));
     }
     $variables['style_image_path'] = "'{$imagePath}'";
     // apply overrides
     if (isset($variables['overrideLess'])) {
         $lines = explode("\n", StringUtil::unifyNewlines($variables['overrideLess']));
         foreach ($lines as $line) {
             if (preg_match('~^@([a-zA-Z]+): ?([@a-zA-Z0-9 ,\\.\\(\\)\\%\\#-]+);$~', $line, $matches)) {
                 $variables[$matches[1]] = $matches[2];
             }
         }
         unset($variables['overrideLess']);
     }
     // add options as LESS variables
     foreach (Option::getOptions() as $constantName => $option) {
         if (in_array($option->optionType, array('boolean', 'integer'))) {
             $variables['wcf_option_' . mb_strtolower($constantName)] = '~"' . $option->optionValue . '"';
         }
     }
     // compile
     $this->compiler->setVariables($variables);
     $content = "/* stylesheet for '" . $stylesheet->getTitle() . "', generated on " . gmdate('r') . " -- DO NOT EDIT */\n\n";
     $content .= $this->compiler->compile($stylesheet->less);
     // compress stylesheet
     $lines = explode("\n", $content);
     $content = $lines[0] . "\n" . $lines[1] . "\n";
     for ($i = 2, $length = count($lines); $i < $length; $i++) {
         $line = trim($lines[$i]);
         $content .= $line;
         switch (substr($line, -1)) {
             case ',':
                 $content .= ' ';
                 break;
             case '}':
                 $content .= "\n";
                 break;
         }
         if (substr($line, 0, 6) == '@media') {
             $content .= "\n";
         }
     }
     // write stylesheet
     $filename = $stylesheet->getLocation($styleID);
     file_put_contents($filename, $content);
     FileUtil::makeWritable($filename);
     // write rtl stylesheet
     $content = StyleUtil::convertCSSToRTL($content);
     $filename = $stylesheet->getLocation($styleID, true);
     file_put_contents($filename, $content);
     FileUtil::makeWritable($filename);
 }
Пример #3
0
 /**
  * Converts the file of this style to a RTL ("right-to-left") version. 
  */
 public function writeStyleFileRTL()
 {
     // get contents of LTR version
     $contents = file_get_contents(WCF_DIR . 'style/style-' . $this->styleID . '.css');
     // convert ltr to rtl
     $contents = StyleUtil::convertCSSToRTL($contents);
     // write file
     $file = new File(WCF_DIR . 'style/style-' . $this->styleID . '-rtl.css');
     $file->write($contents);
     $file->close();
     @chmod(WCF_DIR . 'style/style-' . $this->styleID . '-rtl.css', 0777);
 }
Пример #4
0
	/**
	 * Compiles LESS stylesheets into one CSS-stylesheet and writes them
	 * to filesystem. Please be aware not to append '.css' within $filename!
	 * 
	 * @param	string			$filename
	 * @param	array<string>		$files
	 * @param	array<string>		$variables
	 * @param	string			$individualLess
	 * @param	wcf\system\Callback	$callback
	 */
	protected function compileStylesheet($filename, array $files, array $variables, $individualLess, Callback $callback) {
		// build LESS bootstrap
		$less = $this->bootstrap($variables);
		foreach ($files as $file) {
			$less .= $this->prepareFile($file);
		}
		
		// append individual CSS/LESS
		if ($individualLess) {
			$less .= $individualLess;
		}
		
		try {
			$content = $this->compiler->compile($less);
		}
		catch (\Exception $e) {
			throw new SystemException("Could not compile LESS: ".$e->getMessage(), 0, '', $e);
		}
		
		$content = $callback($content);
		
		// write stylesheet
		file_put_contents($filename.'.css', $content);
		
		// convert stylesheet to RTL
		$content = StyleUtil::convertCSSToRTL($content);
		
		// write stylesheet for RTL
		file_put_contents($filename.'-rtl.css', $content);
	}
Пример #5
0
 /**
  * Converts the file of this style to a RTL ("right-to-left") version. 
  */
 public static function updateStyleFileRTL()
 {
     // get contents of LTR version
     $contents = file_get_contents(WCF_DIR . 'acp/style/style-ltr.css');
     // convert ltr to rtl
     $contents = StyleUtil::convertCSSToRTL($contents);
     // write file
     $file = new File(WCF_DIR . 'acp/style/style-rtl.css');
     $file->write($contents);
     // close file
     $file->close();
     @chmod(WCF_DIR . 'acp/style/style-rtl.css', 0777);
 }