/** * @see PackageInstallationPlugin::install() */ public function install() { parent::install(); require_once WCF_DIR . 'lib/data/style/StyleEditor.class.php'; $instructions = $this->installation->getInstructions(); $styles = $instructions['style']; if (count($styles) && isset($styles['cdata'])) { $styles = array($styles); } // Install each <style>-tag from package.xml foreach ($styles as $styleData) { // extract style tar from package archive // No <style>-tag in the instructions in package.xml if (!isset($styleData['cdata']) || !$styleData['cdata']) { return false; } // extract style tar $filename = $this->installation->getArchive()->extractTar($styleData['cdata'], 'style_'); // import style $style = StyleEditor::import($filename, $this->installation->getPackageID()); // set wcf basic style as default if (isset($styleData['default'])) { $style->setAsDefault(); } // delete tmp file @unlink($filename); } }
/** * @see Form::validate() */ public function validate() { parent::validate(); if (!empty($this->filename)) { // import style $this->style = StyleEditor::import($this->filename, PACKAGE_ID, $this->destinationStyle !== null && $this->destinationStyle->styleID ? $this->destinationStyle : null); } else { // import destination if ($this->destinationStyle !== null && !$this->destinationStyle->styleID) { throw new UserInputException('destinationStyleID'); } // upload style if ($this->styleUpload && $this->styleUpload['error'] != 4) { if ($this->styleUpload['error'] != 0) { throw new UserInputException('styleUpload', 'uploadFailed'); } $this->newFilename = $this->styleUpload['tmp_name']; try { $this->styleData = StyleEditor::getStyleData($this->styleUpload['tmp_name']); } catch (SystemException $e) { throw new UserInputException('styleUpload', 'invalid'); } // copy file $newFilename = FileUtil::getTemporaryFilename('style_'); if (@move_uploaded_file($this->styleUpload['tmp_name'], $newFilename)) { $this->newFilename = $newFilename; } } else { if ($this->styleURL != 'http://') { if (StringUtil::indexOf($this->styleURL, 'http://') !== 0) { throw new UserInputException('styleURL', 'downloadFailed'); } try { $this->newFilename = FileUtil::downloadFileFromHttp($this->styleURL, 'style'); } catch (SystemException $e) { throw new UserInputException('styleURL', 'downloadFailed'); } try { $this->styleData = StyleEditor::getStyleData($this->newFilename); } catch (SystemException $e) { throw new UserInputException('styleURL', 'invalid'); } } else { throw new UserInputException('styleUpload'); } } } }