/** * Reads the data of a variables.xml file. * * @param string $filename * @param string $content * @return array */ public static function readVariablesData($filename, $content) { // open variables.xml $xml = new XML(); $xml->loadXML($filename, $content); $xpath = $xml->xpath(); $variables = $xml->xpath()->query('/ns:variables/ns:variable'); $data = array(); foreach ($variables as $variable) { $data[$variable->getAttribute('name')] = $variable->nodeValue; } return $data; }
/** * Parses a stream containing info from a packages_update.xml. * * @param string $content * @return array $allNewPackages */ protected static function parsePackageUpdateXML($content) { // load xml document $xml = new XML(); $xml->loadXML('packageUpdateServer.xml', $content); $xpath = $xml->xpath(); // loop through <package> tags inside the <section> tag. $allNewPackages = array(); $packages = $xpath->query('/ns:section[@name=\'packages\']/ns:package'); foreach ($packages as $package) { if (!Package::isValidPackageName($package->getAttribute('name'))) { throw new SystemException("'" . $package->getAttribute('name') . "' is not a valid package name."); } $allNewPackages[$package->getAttribute('name')] = self::parsePackageUpdateXMLBlock($xpath, $package); } return $allNewPackages; }
/** * Extracts the language file and parses it with * SimpleXML. If the specified language file * was not found, an error message is thrown. * * @param string $filename * @return wcf\util\XML xml */ protected function readLanguage($filename) { // search language files in package archive // throw error message if not found if (($fileIndex = $this->installation->getArchive()->getTar()->getIndexByFilename($filename)) === false) { throw new SystemException("language file '" . $filename . "' not found."); } // extract language file and parse with DOMDocument $xml = new XML(); $xml->loadXML($filename, $this->installation->getArchive()->getTar()->extractToString($fileIndex)); return $xml; }
/** * Parses XML response from language server. * * @param string $xmlResponse */ protected function parseResponse($xmlResponse) { // parse xml $xml = new XML(); $xml->loadXML('languageServerResponse.xml', $xmlResponse); $xpath = $xml->xpath(); // parse variables $variables = array(); $packages = $xpath->query('/ns:language/ns:package'); foreach ($packages as $package) { $packageName = $package->getAttribute('name'); $variables[$packageName] = array(); $categories = $xpath->query('child::ns:category', $package); foreach ($categories as $category) { $categoryName = $category->getAttribute('name'); $variables[$packageName][$categoryName] = array(); $items = $xpath->query('child::ns:item', $category); foreach ($items as $item) { $variables[$packageName][$categoryName][$item->getAttribute('name')] = $item->nodeValue; } } } // try to resolve packages $conditions = new PreparedStatementConditionBuilder(); $conditions->add("package IN (?)", array(array_keys($variables))); $sql = "SELECT\tpackageID, package\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $packages = array(); while ($row = $statement->fetchArray()) { $packages[$row['package']] = $row['packageID']; } // ignore variables if no package is known if (empty($packages)) { return; } $this->importVariables($variables, $packages); }
protected function readXML($tar) { $xml = 'cmsData.xml'; if ($tar->getIndexByFileName($xml) === false) { throw new SystemException("Unable to find required file '" . $xml . "' in the import archive"); } $xmlData = new XML(); $xmlData->loadXML($xml, $tar->extractToString($tar->getIndexByFileName($xml))); $xpath = $xmlData->xpath(); $root = $xpath->query('/ns:data')->item(0); $test = $xpath->query('//data')->item(0); if ($test !== null) { $this->cmsUrl = $test->getAttribute('cmsUrl'); $this->api = $test->getAttribute('api'); } $items = $xpath->query('child::*', $root); $data = array(); $i = 0; foreach ($items as $item) { foreach ($xpath->query('child::*', $item) as $child) { foreach ($xpath->query('child::*', $child) as $property) { if ($property->tagName == 'contentTypeID') { $data[$item->tagName][$i][$property->tagName] = ObjectTypeCache::getInstance()->getObjectTypeIDByName('de.codequake.cms.content.type', $property->nodeValue); } else { if ($property->tagName == 'parentID' && $property->nodeValue == '' || $property->tagName == 'menuItemID') { $data[$item->tagName][$i][$property->tagName] = null; } else { $data[$item->tagName][$i][$property->tagName] = $property->nodeValue; } } } $i++; } } return $data; }
/** * Parses a stream containing info from a packages_update.xml. * * @param string $content * @return array $allNewPackages */ protected function parsePackageUpdateXML($content) { // load xml document $xml = new XML(); $xml->loadXML('packageUpdateServer.xml', $content); $xpath = $xml->xpath(); $allNewPackages = array(); $packages = $xpath->query('/ns:section/ns:package'); foreach ($packages as $package) { if (!Package::isValidPackageName($package->getAttribute('name'))) { throw new SystemException("'" . $package->getAttribute('name') . "' is not a valid package name."); } $allNewPackages[$package->getAttribute('name')] = $this->parsePackageUpdateXMLBlock($xpath, $package); } return $allNewPackages; }
/** * Extracts information about this package (parses package.xml). */ protected function readPackageInfo() { // search package.xml in package archive // throw error message if not found if ($this->tar->getIndexByFilename(self::INFO_FILE) === false) { throw new SystemException("package information file '".(self::INFO_FILE)."' not found in '".$this->archive."'"); } // extract package.xml, parse with SimpleXML // and compile an array with XML::getElementTree() $xml = new XML(); try { $xml->loadXML(self::INFO_FILE, $this->tar->extractToString(self::INFO_FILE)); } catch (\Exception $e) { // bugfix to avoid file caching problems $xml->loadXML(self::INFO_FILE, $this->tar->extractToString(self::INFO_FILE)); } // parse xml $xpath = $xml->xpath(); $package = $xpath->query('/ns:package')->item(0); // package name $packageName = $package->getAttribute('name'); if (!Package::isValidPackageName($packageName)) { // package name is not a valid package identifier throw new SystemException("'".$packageName."' is not a valid package name."); } $this->packageInfo['name'] = $packageName; // get package information $packageInformation = $xpath->query('./ns:packageinformation', $package)->item(0); $elements = $xpath->query('child::*', $packageInformation); foreach ($elements as $element) { switch ($element->tagName) { case 'packagename': case 'packagedescription': case 'readme': case 'license': if (!isset($this->packageInfo[$element->tagName])) $this->packageInfo[$element->tagName] = array(); $languageCode = 'default'; if ($element->hasAttribute('language')) { $languageCode = $element->getAttribute('language'); } // fix case-sensitive names $name = $element->tagName; if ($name == 'packagename') $name = 'packageName'; else if ($name == 'packagedescription') $name = 'packageDescription'; $this->packageInfo[$name][$languageCode] = $element->nodeValue; break; case 'isapplication': $this->packageInfo['isApplication'] = intval($element->nodeValue); break; case 'packageurl': $this->packageInfo['packageURL'] = $element->nodeValue; break; case 'version': if (!Package::isValidVersion($element->nodeValue)) { throw new SystemException("package version '".$element->nodeValue."' is invalid"); } $this->packageInfo['version'] = $element->nodeValue; break; case 'date': DateUtil::validateDate($element->nodeValue); $this->packageInfo['date'] = strtotime($element->nodeValue); break; } } // get author information $authorInformation = $xpath->query('./ns:authorinformation', $package)->item(0); $elements = $xpath->query('child::*', $authorInformation); foreach ($elements as $element) { $tagName = ($element->tagName == 'authorurl') ? 'authorURL' : $element->tagName; $this->authorInfo[$tagName] = $element->nodeValue; } // get required packages $elements = $xpath->query('child::ns:requiredpackages/ns:requiredpackage', $package); foreach ($elements as $element) { if (!Package::isValidPackageName($element->nodeValue)) { throw new SystemException("'".$element->nodeValue."' is not a valid package name."); } // read attributes $data = array('name' => $element->nodeValue); $attributes = $xpath->query('attribute::*', $element); foreach ($attributes as $attribute) { $data[$attribute->name] = $attribute->value; } $this->requirements[$element->nodeValue] = $data; } // get optional packages $elements = $xpath->query('child::ns:optionalpackages/ns:optionalpackage', $package); foreach ($elements as $element) { if (!Package::isValidPackageName($element->nodeValue)) { throw new SystemException("'".$element->nodeValue."' is not a valid package name."); } // read attributes $data = array('name' => $element->nodeValue); $attributes = $xpath->query('attribute::*', $element); foreach ($attributes as $attribute) { $data[$attribute->name] = $attribute->value; } $this->optionals[] = $data; } // get excluded packages $elements = $xpath->query('child::ns:excludedpackages/ns:excludedpackage', $package); foreach ($elements as $element) { if (!Package::isValidPackageName($element->nodeValue)) { throw new SystemException("'".$element->nodeValue."' is not a valid package name."); } // read attributes $data = array('name' => $element->nodeValue); $attributes = $xpath->query('attribute::*', $element); foreach ($attributes as $attribute) { $data[$attribute->name] = $attribute->value; } $this->excludedPackages[] = $data; } // get instructions $elements = $xpath->query('./ns:instructions', $package); foreach ($elements as $element) { $instructionData = array(); $instructions = $xpath->query('./ns:instruction', $element); foreach ($instructions as $instruction) { $data = array(); $attributes = $xpath->query('attribute::*', $instruction); foreach ($attributes as $attribute) { $data[$attribute->name] = $attribute->value; } $instructionData[] = array( 'attributes' => $data, 'pip' => $instruction->getAttribute('type'), 'value' => $instruction->nodeValue ); } $fromVersion = $element->getAttribute('fromversion'); $type = $element->getAttribute('type'); if ($type == 'install') { $this->instructions['install'] = $instructionData; } else { $this->instructions['update'][$fromVersion] = $instructionData; } } // get php requirements $requirements = $xpath->query('./ns:phprequirements', $package); foreach ($requirements as $requirement) { $elements = $xpath->query('child::*', $requirement); foreach ($elements as $element) { switch ($element->tagName) { case 'version': $this->phpRequirements['version'] = $element->nodeValue; break; case 'setting': $this->phpRequirements['settings'][$element->getAttribute('name')] = $element->nodeValue; break; case 'extension': $this->phpRequirements['extensions'][] = $element->nodeValue; break; case 'function': $this->phpRequirements['functions'][] = $element->nodeValue; break; case 'class': $this->phpRequirements['classes'][] = $element->nodeValue; break; } } } // add com.woltlab.wcf to package requirements if (!isset($this->requirements['com.woltlab.wcf']) && $this->packageInfo['name'] != 'com.woltlab.wcf') { $this->requirements['com.woltlab.wcf'] = array('name' => 'com.woltlab.wcf'); } if ($this->package != null) { $validFromVersion = null; foreach ($this->instructions['update'] as $fromVersion => $update) { if (Package::checkFromversion($this->package->packageVersion, $fromVersion)) { $validFromVersion = $fromVersion; break; } } if ($validFromVersion === null) { $this->instructions['update'] = array(); } else { $this->instructions['update'] = $this->instructions['update'][$validFromVersion]; } } // set default values if (!isset($this->packageInfo['isApplication'])) $this->packageInfo['isApplication'] = 0; if (!isset($this->packageInfo['packageURL'])) $this->packageInfo['packageURL'] = ''; }