/** * Extracts the requested file in the package archive to the temp folder * and returns the path to the extracted file. * * @param string $filename * @param string $tempPrefix * @return string */ public function extractTar($filename, $tempPrefix = 'package_') { // search the requested tar archive in our package archive. // throw error message if not found. if (($fileIndex = $this->tar->getIndexByFilename($filename)) === false) { throw new PackageValidationException(PackageValidationException::FILE_NOT_FOUND, array('archive' => $this->archive, 'targetArchive' => $filename)); } // requested tar archive was found $fileInfo = $this->tar->getFileInfo($fileIndex); $filename = FileUtil::getTemporaryFilename($tempPrefix, preg_replace('!^.*?(\\.(?:tar\\.gz|tgz|tar))$!i', '\\1', $fileInfo['filename'])); $this->tar->extract($fileIndex, $filename); return $filename; }
/** * Extracts the requested file in the package archive to the temp folder * and returns the path to the extracted file. * * @param string $filename * @param string $tempPrefix * @return string */ public function extractTar($filename, $tempPrefix = 'package_') { // search the requested tar archive in our package archive. // throw error message if not found. if (($fileIndex = $this->tar->getIndexByFilename($filename)) === false) { throw new SystemException("tar archive '".$filename."' not found in '".$this->archive."'."); } // requested tar archive was found $fileInfo = $this->tar->getFileInfo($fileIndex); $filename = FileUtil::getTemporaryFilename($tempPrefix, preg_replace('!^.*?(\.(?:tar\.gz|tgz|tar))$!i', '\\1', $fileInfo['filename'])); $this->tar->extract($fileIndex, $filename); return $filename; }
/** * Reads the data of a style exchange format file. * * @param \wcf\system\io\Tar $tar * @return array */ public static function readStyleData(Tar $tar) { // search style.xml $index = $tar->getIndexByFilename(self::INFO_FILE); if ($index === false) { throw new SystemException("unable to find required file '" . self::INFO_FILE . "' in style archive"); } // open style.xml $xml = new XML(); $xml->loadXML(self::INFO_FILE, $tar->extractToString($index)); $xpath = $xml->xpath(); $data = array('name' => '', 'description' => array(), 'version' => '', 'image' => '', 'copyright' => '', 'default' => false, 'license' => '', 'authorName' => '', 'authorURL' => '', 'templates' => '', 'images' => '', 'variables' => '', 'date' => '0000-00-00', 'imagesPath' => ''); $categories = $xpath->query('/ns:style/*'); foreach ($categories as $category) { switch ($category->tagName) { case 'author': $elements = $xpath->query('child::*', $category); foreach ($elements as $element) { switch ($element->tagName) { case 'authorname': $data['authorName'] = $element->nodeValue; break; case 'authorurl': $data['authorURL'] = $element->nodeValue; break; } } break; case 'files': $elements = $xpath->query('child::*', $category); foreach ($elements as $element) { $data[$element->tagName] = $element->nodeValue; if ($element->hasAttribute('path')) { $data[$element->tagName . 'Path'] = $element->getAttribute('path'); } } break; case 'general': $elements = $xpath->query('child::*', $category); foreach ($elements as $element) { switch ($element->tagName) { case 'date': DateUtil::validateDate($element->nodeValue); $data['date'] = $element->nodeValue; break; case 'default': $data['default'] = true; break; case 'description': if ($element->hasAttribute('language')) { $data['description'][$element->getAttribute('language')] = $element->nodeValue; } break; case 'stylename': $data['name'] = $element->nodeValue; break; case 'version': if (!Package::isValidVersion($element->nodeValue)) { throw new SystemException("style version '" . $element->nodeValue . "' is invalid"); } $data['version'] = $element->nodeValue; break; case 'copyright': case 'image': case 'license': $data[$element->tagName] = $element->nodeValue; break; } } break; } } if (empty($data['name'])) { throw new SystemException("required tag 'stylename' is missing in '" . self::INFO_FILE . "'"); } if (empty($data['variables'])) { throw new SystemException("required tag 'variables' is missing in '" . self::INFO_FILE . "'"); } // search variables.xml $index = $tar->getIndexByFilename($data['variables']); if ($index === false) { throw new SystemException("unable to find required file '" . $data['variables'] . "' in style archive"); } // open variables.xml $data['variables'] = self::readVariablesData($data['variables'], $tar->extractToString($index)); return $data; }
/** * Reads the data of a style exchange format file. * * @param wcf\system\io\Tar $tar * @return array data */ public static function readStyleData(Tar $tar) { // search style.xml $i = $tar->getIndexByFilename(self::INFO_FILE); if ($i === false) { throw new SystemException("unable to find required file '" . self::INFO_FILE . "' in style archive"); } // open style.xml $styleXML = new XML(); $styleXML->loadString($tar->extractToString($i)); $xmlContent = $styleXML->getElementTree('style'); $data = array('name' => '', 'description' => '', 'version' => '', 'image' => '', 'copyright' => '', 'license' => '', 'authorName' => '', 'authorURL' => '', 'templates' => '', 'images' => '', 'variables' => '', 'date' => '0000-00-00', 'icons' => ''); foreach ($xmlContent['children'] as $child) { switch ($child['name']) { case 'general': foreach ($child['children'] as $general) { switch ($general['name']) { case 'stylename': $data['name'] = $general['cdata']; break; case 'description': case 'version': case 'date': case 'image': case 'copyright': case 'license': $data[$general['name']] = $general['cdata']; break; } } break; case 'author': foreach ($child['children'] as $author) { switch ($author['name']) { case 'authorname': $data['authorName'] = $author['cdata']; break; case 'authorurl': $data['authorURL'] = $author['cdata']; break; } } break; case 'files': foreach ($child['children'] as $files) { switch ($files['name']) { case 'templates': case 'images': case 'variables': case 'icons': $data[$files['name']] = $files['cdata']; break; } } break; } } if (empty($data['name'])) { throw new SystemException("required tag 'stylename' is missing in '" . self::INFO_FILE . "'"); } if (empty($data['variables'])) { throw new SystemException("required tag 'variables' is missing in '" . self::INFO_FILE . "'"); } // search variables.xml $i = $tar->getIndexByFilename($data['variables']); if ($i === false) { throw new SystemException("unable to find required file '" . $data['variables'] . "' in style archive"); } // open variables.xml $data['variables'] = self::readVariablesData($tar->extractToString($i)); return $data; }