/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
	 */
	public function install() {
		parent::install();
		
		// get package installation dir
		$dir = $this->installation->getPackage()->packageDir;
		if (empty($dir)) {
			if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install') {
				// application
				// prompt package dir
				$dir = $this->promptPackageDir();
			}
			
			// save package dir
			if (!empty($dir)) {
				$package = new Package($this->installation->getPackageID());
				$packageEditor = new PackageEditor($package);
				$packageEditor->update(array('packageDir' => $dir));
				
				$this->installation->getPackage()->packageDir = $dir;
			}
		}
		
		// absolute path to package dir
		$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$dir));
		
		// extract files.tar to temp folder
		$sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'files_');
		
		// create file handler
		$fileHandler = new FilesFileHandler($this->installation);
		
		// extract content of files.tar
		$fileInstaller = $this->installation->extractFiles($packageDir, $sourceFile, $fileHandler);
		
		// if this a an application, write config.inc.php for this package
		if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install') {
			// touch file
			$fileInstaller->touchFile(PackageInstallationDispatcher::CONFIG_FILE);
			
			// create file
			Package::writeConfigFile($this->installation->getPackageID());
			
			// log file
			$sql = "INSERT INTO	wcf".WCF_N."_package_installation_file_log
						(packageID, filename)
				VALUES		(?, 'config.inc.php')";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute(array($this->installation->getPackageID()));
		}
		
		// delete temporary sourceArchive
		@unlink($sourceFile);
		
		// update acp style file
		StyleUtil::updateStyleFile();
	}
 /**
  * @see	\wcf\system\package\plugin\IPackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     $abbreviation = 'wcf';
     if (isset($this->instruction['attributes']['application'])) {
         $abbreviation = $this->instruction['attributes']['application'];
     } else {
         if ($this->installation->getPackage()->isApplication) {
             $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package);
         }
     }
     // absolute path to package dir
     $packageDir = Application::getDirectory($abbreviation);
     // extract files.tar to temp folder
     $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'files_');
     // create file handler
     $fileHandler = new FilesFileHandler($this->installation, $abbreviation);
     // extract content of files.tar
     $fileInstaller = $this->installation->extractFiles($packageDir, $sourceFile, $fileHandler);
     // if this a an application, write config.inc.php for this package
     if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install' && $abbreviation != 'wcf') {
         // touch file
         $fileInstaller->touchFile(PackageInstallationDispatcher::CONFIG_FILE);
         // create file
         Package::writeConfigFile($this->installation->getPackageID());
         // log file
         $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\t\t\t(packageID, filename, application)\n\t\t\t\tVALUES\t\t(?, ?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->installation->getPackageID(), 'config.inc.php', Package::getAbbreviation($this->installation->getPackage()->package)));
         // load application
         WCF::loadRuntimeApplication($this->installation->getPackageID());
     }
     // delete temporary sourceArchive
     @unlink($sourceFile);
     // update acp style file
     StyleUtil::updateStyleFile();
 }
 /**
  * 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');
 }
 /**
  * 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);
 }
Exemple #5
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);
	}
Exemple #6
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);
 }
Exemple #7
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);
 }