Added ability to export styles as package
authorAlexander Ebert <ebert@woltlab.com>
Fri, 12 Oct 2012 17:33:41 +0000 (19:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 12 Oct 2012 17:33:41 +0000 (19:33 +0200)
wcfsetup/install/files/lib/data/style/StyleEditor.class.php

index 593c76d9931fd59b67266b36b2701a3dbc439d6e..c2bcdc7fa7a9ec43e6bf806a1dbb0f25ddc95c3d 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\data\style;
+use wcf\system\package\PackageArchive;
+
 use wcf\data\package\Package;
 use wcf\data\template\group\TemplateGroup;
 use wcf\data\template\group\TemplateGroupEditor;
@@ -535,8 +537,9 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
         * @param       boolean         $templates
         * @param       boolean         $images
         * @param       boolean         $icons
+        * @param       string          $packageName
         */
-       public function export($templates = false, $images = false, $icons = false) {
+       public function export($templates = false, $images = false, $icons = false, $packageName = '') {
                // create style tar
                $styleTarName = FileUtil::getTemporaryFilename('style_', '.tgz');
                $styleTar = new TarWriter($styleTarName, true);
@@ -682,7 +685,51 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                
                // output file content
                $styleTar->create();
-               readfile($styleTarName);
+               
+               // 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::unifyDirSeperator($styleTarName);
+                       $packageTar->add($styleTarName, '', dirname($styleTarName));
+                       
+                       // create package.xml
+                       $string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<package name=\"".$packageName."\" xmlns=\"http://www.woltlab.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/package.xsd\">\n";
+                       
+                       $string .= "\t<packageinformation>\n";
+                       $string .= "\t\t<packagename><![CDATA[".StringUtil::escapeCDATA($this->styleName)."]]></packagename>\n";
+                       $string .= "\t\t<packagedescription><![CDATA[".StringUtil::escapeCDATA($this->styleDescription)."]]></packagedescription>\n";
+                       $string .= "\t\t<version><![CDATA[".StringUtil::escapeCDATA($this->styleVersion)."]]></version>\n";
+                       $string .= "\t\t<date><![CDATA[".StringUtil::escapeCDATA($this->styleDate)."]]></date>\n";
+                       $string .= "\t</packageinformation>\n";
+                       
+                       $string .= "\t<authorinformation>\n";
+                       $string .= "\t\t<author><![CDATA[".StringUtil::escapeCDATA($this->authorName)."]]></author>\n";
+                       if ($this->authorURL) $string .= "\t\t<authorurl><![CDATA[".StringUtil::escapeCDATA($this->authorURL)."]]></authorurl>\n";
+                       $string .= "\t</authorinformation>\n";
+                       
+                       $string .= "\t<instructions type=\"install\">\n";
+                       $string .= "\t\t<instruction type=\"style\">".basename($styleTarName)."</instruction>\n";
+                       $string .= "\t</instructions>\n";
+                       
+                       $string .= "</package>\n";
+                       
+                       // append package info file to package tar
+                       $packageTar->addString(PackageArchive::INFO_FILE, $string);
+                       
+                       $packageTar->create();
+                       readfile($packageTarName);
+                       @unlink($packageTarName);
+               }
+               
                @unlink($styleTarName);
        }