예제 #1
0
 protected function tarFiles()
 {
     $files = new DirectoryUtil(CMS_DIR . 'files/');
     $tar = new TarWriter(FileUtil::getTempFolder() . 'files.tar');
     $fileList = $files->getFiles(SORT_ASC, new Regex('^' . CMS_DIR . 'files/$'), true);
     $tar->add($fileList, '', CMS_DIR . 'files/');
     $tar->create();
 }
예제 #2
0
 /**
  * Exports this style.
  * 
  * @param	boolean		$templates
  * @param	boolean		$images
  * @param	string		$packageName
  */
 public function export($templates = false, $images = false, $packageName = '')
 {
     // create style tar
     $styleTarName = FileUtil::getTemporaryFilename('style_', '.tgz');
     $styleTar = new TarWriter($styleTarName, true);
     // append style preview image
     if ($this->image && @file_exists(WCF_DIR . 'images/' . $this->image)) {
         $styleTar->add(WCF_DIR . 'images/' . $this->image, '', FileUtil::addTrailingSlash(dirname(WCF_DIR . 'images/' . $this->image)));
     }
     // fetch style description
     $sql = "SELECT\t\tlanguage.languageCode, language_item.languageItemValue\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item language_item\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_language language\n\t\t\tON\t\t(language.languageID = language_item.languageID)\n\t\t\tWHERE\t\tlanguage_item.languageItem = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->styleDescription));
     $styleDescriptions = array();
     while ($row = $statement->fetchArray()) {
         $styleDescriptions[$row['languageCode']] = $row['languageItemValue'];
     }
     // create style info file
     $xml = new XMLWriter();
     $xml->beginDocument('style', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/style.xsd');
     // general block
     $xml->startElement('general');
     $xml->writeElement('stylename', $this->styleName);
     // style description
     foreach ($styleDescriptions as $languageCode => $value) {
         $xml->writeElement('description', $value, array('language' => $languageCode));
     }
     $xml->writeElement('date', $this->styleDate);
     $xml->writeElement('version', $this->styleVersion);
     if ($this->image) {
         $xml->writeElement('image', $this->image);
     }
     if ($this->copyright) {
         $xml->writeElement('copyright', $this->copyright);
     }
     if ($this->license) {
         $xml->writeElement('license', $this->license);
     }
     $xml->endElement();
     // author block
     $xml->startElement('author');
     $xml->writeElement('authorname', $this->authorName);
     if ($this->authorURL) {
         $xml->writeElement('authorurl', $this->authorURL);
     }
     $xml->endElement();
     // files block
     $xml->startElement('files');
     $xml->writeElement('variables', 'variables.xml');
     if ($templates) {
         $xml->writeElement('templates', 'templates.tar');
     }
     if ($images) {
         $xml->writeElement('images', 'images.tar', array('path' => $this->imagePath));
     }
     $xml->endElement();
     // append style info file to style tar
     $styleTar->addString(self::INFO_FILE, $xml->endDocument());
     unset($string);
     // create variable list
     $xml->beginDocument('variables', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/styleVariables.xsd');
     // get variables
     $sql = "SELECT\t\tvariable.variableName, value.variableValue\n\t\t\tFROM\t\twcf" . WCF_N . "_style_variable_value value\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_style_variable variable\n\t\t\tON\t\t(variable.variableID = value.variableID)\n\t\t\tWHERE\t\tvalue.styleID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->styleID));
     while ($row = $statement->fetchArray()) {
         $xml->writeElement('variable', $row['variableValue'], array('name' => $row['variableName']));
     }
     // append variable list to style tar
     $styleTar->addString('variables.xml', $xml->endDocument());
     unset($string);
     if ($templates && $this->templateGroupID) {
         $templateGroup = new TemplateGroup($this->templateGroupID);
         // create templates tar
         $templatesTarName = FileUtil::getTemporaryFilename('templates', '.tar');
         $templatesTar = new TarWriter($templatesTarName);
         FileUtil::makeWritable($templatesTarName);
         // append templates to tar
         // get templates
         $sql = "SELECT\t\ttemplate.*, package.package\n\t\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\t\tWHERE\t\ttemplate.templateGroupID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->templateGroupID));
         while ($row = $statement->fetchArray()) {
             $packageDir = 'com.woltlab.wcf';
             $package = null;
             if ($row['application'] != 'wcf') {
                 $application = ApplicationHandler::getInstance()->getApplication($row['application']);
                 $package = PackageCache::getInstance()->getPackage($application->packageID);
                 $packageDir = $package->package;
             } else {
                 $application = ApplicationHandler::getInstance()->getWCF();
                 $package = PackageCache::getInstance()->getPackage($application->packageID);
             }
             $filename = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir . 'templates/' . $templateGroup->templateGroupFolderName)) . $row['templateName'] . '.tpl';
             $templatesTar->add($filename, $packageDir, dirname($filename));
         }
         // append templates tar to style tar
         $templatesTar->create();
         $styleTar->add($templatesTarName, 'templates.tar', $templatesTarName);
         @unlink($templatesTarName);
     }
     if ($images && ($this->imagePath && $this->imagePath != 'images/')) {
         // create images tar
         $imagesTarName = FileUtil::getTemporaryFilename('images_', '.tar');
         $imagesTar = new TarWriter($imagesTarName);
         FileUtil::makeWritable($imagesTarName);
         // append images to tar
         $path = FileUtil::addTrailingSlash(WCF_DIR . $this->imagePath);
         if (file_exists($path) && is_dir($path)) {
             $handle = opendir($path);
             $regEx = new Regex('\\.(jpg|jpeg|gif|png|svg)$', Regex::CASE_INSENSITIVE);
             while (($file = readdir($handle)) !== false) {
                 if (is_file($path . $file) && $regEx->match($file)) {
                     $imagesTar->add($path . $file, '', $path);
                 }
             }
         }
         // append images tar to style tar
         $imagesTar->create();
         $styleTar->add($imagesTarName, 'images.tar', $imagesTarName);
         @unlink($imagesTarName);
     }
     // output file content
     $styleTar->create();
     // export as style package
     if (empty($packageName)) {
         readfile($styleTarName);
     } else {
         // export as package
         // create package tar
         $packageTarName = FileUtil::getTemporaryFilename('package_', '.tar.gz');
         $packageTar = new TarWriter($packageTarName, true);
         // append style tar
         $styleTarName = FileUtil::unifyDirSeparator($styleTarName);
         $packageTar->add($styleTarName, '', FileUtil::addTrailingSlash(dirname($styleTarName)));
         // create package.xml
         $xml->beginDocument('package', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/package.xsd', array('name' => $packageName));
         $xml->startElement('packageinformation');
         $xml->writeElement('packagename', $this->styleName);
         // description
         foreach ($styleDescriptions as $languageCode => $value) {
             $xml->writeElement('packagedescription', $value, array('language' => $languageCode));
         }
         $xml->writeElement('version', $this->styleVersion);
         $xml->writeElement('date', $this->styleDate);
         $xml->endElement();
         $xml->startElement('authorinformation');
         $xml->writeElement('author', $this->authorName);
         if ($this->authorURL) {
             $xml->writeElement('authorurl', $this->authorURL);
         }
         $xml->endElement();
         $xml->startElement('requiredpackages');
         $xml->writeElement('requiredpackage', 'com.woltlab.wcf', array('minversion' => PackageCache::getInstance()->getPackageByIdentifier('com.woltlab.wcf')->packageVersion));
         $xml->endElement();
         $xml->startElement('excludedpackages');
         $xml->writeElement('excludedpackage', 'com.woltlab.wcf', array('version' => self::EXCLUDE_WCF_VERSION));
         $xml->endElement();
         $xml->startElement('instructions', array('type' => 'install'));
         $xml->writeElement('instruction', basename($styleTarName), array('type' => 'style'));
         $xml->endElement();
         // append package info file to package tar
         $packageTar->addString(PackageArchive::INFO_FILE, $xml->endDocument());
         $packageTar->create();
         readfile($packageTarName);
         @unlink($packageTarName);
     }
     @unlink($styleTarName);
 }
예제 #3
0
 /**
  * Exports this style.
  * 
  * @param	boolean 	$templates
  * @param	boolean		$images
  * @param	boolean		$icons
  */
 public function export($templates = false, $images = false, $icons = false)
 {
     // create style tar
     $styleTarName = FileUtil::getTemporaryFilename('style_', '.tgz');
     $styleTar = new TarWriter($styleTarName, true);
     // append style preview image
     if ($this->image && @file_exists(WCF_DIR . $this->image)) {
         $styleTar->add(WCF_DIR . $this->image, '', FileUtil::addTrailingSlash(dirname(WCF_DIR . $this->image)));
     }
     // create style info file
     $string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE style SYSTEM \"http://www.woltlab.com/DTDs/SXF/style.dtd\">\n<style>\n";
     // general block
     $string .= "\t<general>\n";
     $string .= "\t\t<stylename><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleName) : $this->styleName) . "]]></stylename>\n";
     // style name
     if ($this->styleDescription) {
         $string .= "\t\t<description><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleDescription) : $this->styleDescription) . "]]></description>\n";
     }
     // style description
     if ($this->styleVersion) {
         $string .= "\t\t<version><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleVersion) : $this->styleVersion) . "]]></version>\n";
     }
     // style version
     if ($this->styleDate) {
         $string .= "\t\t<date><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleDate) : $this->styleDate) . "]]></date>\n";
     }
     // style date
     if ($this->image) {
         $string .= "\t\t<image><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', basename($this->image)) : basename($this->image)) . "]]></image>\n";
     }
     // style preview image
     if ($this->copyright) {
         $string .= "\t\t<copyright><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->copyright) : $this->copyright) . "]]></copyright>\n";
     }
     // copyright
     if ($this->license) {
         $string .= "\t\t<license><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->license) : $this->license) . "]]></license>\n";
     }
     // license
     $string .= "\t</general>\n";
     // author block
     $string .= "\t<author>\n";
     if ($this->authorName) {
         $string .= "\t\t<authorname><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->authorName) : $this->authorName) . "]]></authorname>\n";
     }
     // author name
     if ($this->authorURL) {
         $string .= "\t\t<authorurl><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->authorURL) : $this->authorURL) . "]]></authorurl>\n";
     }
     // author URL
     $string .= "\t</author>\n";
     // files block
     $string .= "\t<files>\n";
     $string .= "\t\t<variables>variables.xml</variables>\n";
     // variables
     if ($templates && $this->templateGroupID) {
         $string .= "\t\t<templates>templates.tar</templates>\n";
     }
     // templates
     if ($images) {
         $string .= "\t\t<images>images.tar</images>\n";
     }
     // images
     if ($icons) {
         $string .= "\t\t<icons>icons.tar</icons>\n";
     }
     // icons
     $string .= "\t</files>\n";
     $string .= "</style>";
     // append style info file to style tar
     $styleTar->addString(self::INFO_FILE, $string);
     unset($string);
     // create variable list
     $string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE variables SYSTEM \"http://www.woltlab.com/DTDs/SXF/variables.dtd\">\n<variables>\n";
     // get variables
     $variables = $this->getVariables();
     $exportImages = array();
     foreach ($variables as $name => $value) {
         // search images
         if ($images && $value) {
             if (preg_match_all('~([^/\\s\\$]+\\.(?:gif|jpg|jpeg|png))~i', $value, $matches)) {
                 $exportImages = array_merge($exportImages, $matches[1]);
             }
         }
         $string .= "\t<variable name=\"" . StringUtil::encodeHTML($name) . "\"><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $value) : $value) . "]]></variable>\n";
     }
     $string .= "</variables>";
     // append variable list to style tar
     $styleTar->addString('variables.xml', $string);
     unset($string);
     if ($templates && $this->templateGroupID) {
         $templateGroup = new TemplateGroup($this->templateGroupID);
         // create templates tar
         $templatesTarName = FileUtil::getTemporaryFilename('templates', '.tar');
         $templatesTar = new TarWriter($templatesTarName);
         @chmod($templatesTarName, 0777);
         // append templates to tar
         // get templates
         $sql = "SELECT\t\ttemplate.*, package.package, package.packageDir,\n\t\t\t\t\t\tparent_package.package AS parentPackage, parent_package.packageDir AS parentPackageDir\n\t\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package parent_package\n\t\t\t\tON\t\t(parent_package.packageID = package.parentPackageID)\n\t\t\t\tWHERE\t\ttemplate.templateGroupID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->templateGroupID));
         while ($row = $statement->fetchArray()) {
             $packageDir = 'com.woltlab.wcf';
             if (!empty($row['parentPackageDir'])) {
                 $packageDir = $row['parentPackage'];
             } else {
                 if (!empty($row['packageDir'])) {
                     $packageDir = $row['package'];
                 }
             }
             $filename = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $row['packageDir'] . 'templates/' . $templateGroup->templateGroupFolderName)) . $row['templateName'] . '.tpl';
             $templatesTar->add($filename, $packageDir, dirname($filename));
         }
         // append templates tar to style tar
         $templatesTar->create();
         $styleTar->add($templatesTarName, 'templates.tar', $templatesTarName);
         @unlink($templatesTarName);
     }
     if ($images) {
         // create images tar
         $imagesTarName = FileUtil::getTemporaryFilename('images_', '.tar');
         $imagesTar = new TarWriter($imagesTarName);
         @chmod($imagesTarName, 0777);
         // cache rtl versions
         foreach ($exportImages as $exportImage) {
             if (strpos($exportImage, '-ltr')) {
                 $exportImages[] = str_replace('-ltr', '-rtl', $exportImage);
             }
         }
         // append images to tar
         $path = WCF_DIR . $variables['global.images.location'];
         if (file_exists($path) && is_dir($path)) {
             $handle = opendir($path);
             while (($file = readdir($handle)) !== false) {
                 if (is_file($path . $file) && in_array($file, $exportImages)) {
                     $imagesTar->add($path . $file, '', $path);
                 }
             }
         }
         // append images tar to style tar
         $imagesTar->create();
         $styleTar->add($imagesTarName, 'images.tar', $imagesTarName);
         @unlink($imagesTarName);
     }
     // export icons
     $iconsLocation = FileUtil::addTrailingSlash($variables['global.icons.location']);
     if ($icons && $iconsLocation != 'icon/') {
         // create icons tar
         $iconsTarName = FileUtil::getTemporaryFilename('icons_', '.tar');
         $iconsTar = new TarWriter($iconsTarName);
         @chmod($iconsTar, 0777);
         // get package dirs
         $sql = "SELECT\tpackage, packageDir\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\tWHERE\tisApplication = 1\n\t\t\t\t\tAND (packageDir <> '' OR package = 'com.woltlab.wcf')";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
         while ($row = $statement->fetchArray()) {
             $iconsDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . $iconsLocation;
             $packageIcons = array();
             if (file_exists($iconsDir)) {
                 $icons = glob($iconsDir . '*.png');
                 if (is_array($icons)) {
                     foreach ($icons as $icon) {
                         $packageIcons[] = $icon;
                     }
                 }
             }
             if (count($packageIcons)) {
                 $iconsTar->add($packageIcons, $row['package'] . '/', $iconsDir);
             }
         }
         $iconsTar->create();
         $styleTar->add($iconsTarName, 'icons.tar', $iconsTarName);
         @unlink($iconsTarName);
     }
     // output file content
     $styleTar->create();
     readfile($styleTarName);
     @unlink($styleTarName);
 }