/** * @param string $name * @return static */ public function package($name) { if (isset($this->dependencies[$name])) { return $this; } if (!Package::isValidPackageName($name)) { throw new \Exception('Package name is invalid'); } $package = Config::instance()->packageDefinitionManager()->get($name); if (Config::instance()->compiler()) { $package = Config::instance()->compiler()->compilePackage($package); } $this->appendPackage($package); return $this; }
/** * Reads out PackageData * * @param array<array> $package the package array generated in self::readPackages() * @param mixed $version the version to check * @param mixed $field should only one information be returned? * @return mixed either an array with data, or the data wanted in $field */ public static function getPackageData(array $package, $version = null, $field = null) { $data = array(); if ($version === null) { // read firest package for general information $key = array_keys($package); $xml = $package[$key[0]]['xml']->getElementTree('data'); } else { $xml = $package[$version]['xml']->getElementTree('data'); } $data['packageIdentifier'] = $xml['attrs']['name']; $data['isUpdate'] = false; $data['plugin'] = $data['packagename'] = $data['packagedescription'] = $data['standalone'] = null; foreach ($xml['children'] as $child) { switch (StringUtil::toLowerCase($child['name'])) { // read in package information case 'packageinformation': foreach ($child['children'] as $packageInformation) { switch (StringUtil::toLowerCase($packageInformation['name'])) { case 'packagename': if (!isset($data['packageName'])) { $data['packageName'] = $packageInformation['cdata']; } break; case 'packagedescription': if (!isset($data['packageDescription'])) { $data['packageDescription'] = $packageInformation['cdata']; } break; case 'standalone': $data['standalone'] = intval($packageInformation['cdata']); break; case 'promptparent': case 'plugin': if (!Package::isValidPackageName($packageInformation['cdata'])) { $data['plugin'] = null; } $data['plugin'] = $packageInformation['cdata']; break; } } break; // read in author information // read in author information case 'authorinformation': foreach ($child['children'] as $authorInformation) { switch (StringUtil::toLowerCase($authorInformation['name'])) { case 'author': $data['author'] = $authorInformation['cdata']; break; case 'authorurl': $data['authorURL'] = $authorInformation['cdata']; break; } } break; // read in requirements // read in requirements case 'requiredpackages': foreach ($child['children'] as $requiredPackage) { if (Package::isValidPackageName($requiredPackage['cdata'])) { $data['requirements'][$requiredPackage['cdata']] = array('name' => $requiredPackage['cdata']) + $requiredPackage['attrs']; } } break; // get installation and update instructions // get installation and update instructions case 'instructions': if ($child['attrs']['type'] == 'update') { $data['isUpdate'] = true; $data['fromVersions'][] = $child['attrs']['fromversion']; } break; } } if ($field === null) { return $data; } else { return $data[$field]; } }
/** * Parses a stream containing info from a packages_update.xml. * * @param string $content * @return array $allNewPackages */ protected static function parsePackageUpdateXML($content) { // load xml document $xmlObj = new XML(); $xmlObj->loadString($content); // load the <section> tag (which must be the root element). $xml = $xmlObj->getElementTree('section'); $encoding = $xmlObj->getEncoding(); unset($xmlObj); // loop through <package> tags inside the <section> tag. $allNewPackages = array(); foreach ($xml['children'] as $child) { // name attribute is missing, thus this package is not valid if (!isset($child['attrs']['name']) || !$child['attrs']['name']) { throw new SystemException("required 'name' attribute for 'package' tag is missing", 13001); } // the "name" attribute of this <package> tag must be a valid package identifier. if (!Package::isValidPackageName($child['attrs']['name'])) { throw new SystemException("'" . $child['attrs']['name'] . "' is not a valid package name.", 18004); } $package = $child['attrs']['name']; // parse packages_update.xml and fill $packageInfo. $packageInfo = self::parsePackageUpdateXMLBlock($child, $package); // convert enconding if ($encoding != CHARSET) { $packageInfo['packageName'] = StringUtil::convertEncoding($encoding, CHARSET, $packageInfo['packageName']); $packageInfo['packageDescription'] = StringUtil::convertEncoding($encoding, CHARSET, $packageInfo['packageDescription']); $packageInfo['author'] = StringUtil::convertEncoding($encoding, CHARSET, $packageInfo['author']); $packageInfo['authorURL'] = StringUtil::convertEncoding($encoding, CHARSET, $packageInfo['authorURL']); } $allNewPackages[$child['attrs']['name']] = $packageInfo; } unset($xml); 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 . "'", 13000); } // extract package.xml, parse with SimpleXML // and compile an array with XML::getElementTree() $xml = new XML(); try { $xml->loadString($this->tar->extractToString(self::INFO_FILE)); } catch (Exception $e) { // bugfix to avoid file caching problems $xml->loadString($this->tar->extractToString(self::INFO_FILE)); } $xmlContent = $xml->getElementTree('package'); // name attribute is missing, thus this package is not valid if (!isset($xmlContent['attrs']['name']) || !$xmlContent['attrs']['name']) { throw new SystemException("required 'name' attribute for 'package' tag is missing in " . self::INFO_FILE, 13001); } // package name is not a valid package identifier if (!Package::isValidPackageName($xmlContent['attrs']['name'])) { throw new SystemException("'" . $xmlContent['attrs']['name'] . "' is not a valid package name.", 13002); } // assign name attribute and loop through child tags $this->packageInfo['name'] = $xmlContent['attrs']['name']; foreach ($xmlContent['children'] as $child) { switch (StringUtil::toLowerCase($child['name'])) { // read in package information case 'packageinformation': foreach ($child['children'] as $packageInformation) { switch (StringUtil::toLowerCase($packageInformation['name'])) { case 'packagename': if (!isset($this->packageInfo['packageName'])) { $this->packageInfo['packageName'] = array(); } if (isset($packageInformation['attrs']['language'])) { $languageCode = $packageInformation['attrs']['language']; } else { if (isset($packageInformation['attrs']['languagecode'])) { $languageCode = $packageInformation['attrs']['languagecode']; } else { $languageCode = 'default'; } } $this->packageInfo['packageName'][$languageCode] = $packageInformation['cdata']; break; case 'packagedescription': if (!isset($this->packageInfo['packageDescription'])) { $this->packageInfo['packageDescription'] = array(); } if (isset($packageInformation['attrs']['language'])) { $languageCode = $packageInformation['attrs']['language']; } else { if (isset($packageInformation['attrs']['languagecode'])) { $languageCode = $packageInformation['attrs']['languagecode']; } else { $languageCode = 'default'; } } $this->packageInfo['packageDescription'][$languageCode] = $packageInformation['cdata']; break; case 'isunique': $this->packageInfo['isUnique'] = intval($packageInformation['cdata']); break; case 'standalone': $this->packageInfo['standalone'] = intval($packageInformation['cdata']); break; case 'promptparent': case 'plugin': if ($packageInformation['cdata'] != 0 && !Package::isValidPackageName($packageInformation['cdata'])) { throw new SystemException("'" . $packageInformation['cdata'] . "' is not a valid package name.", 13002); } $this->packageInfo['plugin'] = $packageInformation['cdata']; break; case 'version': $this->packageInfo['version'] = $packageInformation['cdata']; break; case 'date': $this->packageInfo['date'] = @strtotime($packageInformation['cdata']); if ($this->packageInfo['date'] === -1 || $this->packageInfo['date'] === false) { throw new SystemException("invalid dateformat '" . $packageInformation['cdata'] . "' in package.xml", 13003); } $this->packageInfo['date'] += 43201; break; case 'packageurl': $this->packageInfo['packageURL'] = $packageInformation['cdata']; break; } } break; // read in author information // read in author information case 'authorinformation': foreach ($child['children'] as $authorInformation) { switch (StringUtil::toLowerCase($authorInformation['name'])) { case 'author': $this->authorInfo['author'] = $authorInformation['cdata']; break; case 'authorurl': $this->authorInfo['authorURL'] = $authorInformation['cdata']; break; } } break; // read in requirements // read in requirements case 'requiredpackages': foreach ($child['children'] as $requiredPackage) { // reference to required package is not a valid package identifier if (!Package::isValidPackageName($requiredPackage['cdata'])) { throw new SystemException("'" . $requiredPackage['cdata'] . "' is not a valid package name.", 13002); } $this->requirements[$requiredPackage['cdata']] = array('name' => $requiredPackage['cdata']) + $requiredPackage['attrs']; } break; // read in optionals // read in optionals case 'optionalpackages': foreach ($child['children'] as $optionalPackage) { // reference to optional package is not a valid package identifier if (!Package::isValidPackageName($optionalPackage['cdata'])) { throw new SystemException("'" . $optionalPackage['cdata'] . "' is not a valid package name.", 13002); } if (!isset($optionalPackage['attrs']['file']) || !$optionalPackage['attrs']['file']) { throw new SystemException("required 'file' attribute for 'optionalPackage' tag is missing in " . self::INFO_FILE, 13001); } $this->optionals[] = array('name' => $optionalPackage['cdata']) + $optionalPackage['attrs']; } break; // read in excluded packages // read in excluded packages case 'excludedpackages': foreach ($child['children'] as $excludedPackage) { // reference to excluded package is not a valid package identifier if (!Package::isValidPackageName($excludedPackage['cdata'])) { throw new SystemException("'" . $excludedPackage['cdata'] . "' is not a valid package name.", 13002); } $this->excludedPackages[$excludedPackage['cdata']] = array('name' => $excludedPackage['cdata']) + $excludedPackage['attrs']; } break; // get installation and update instructions // get installation and update instructions case 'instructions': if ($child['attrs']['type'] == 'update') { if (!isset($child['attrs']['fromversion']) || !$child['attrs']['fromversion']) { throw new SystemException("required 'fromversion' attribute for 'instructions type=update' tag is missing in " . self::INFO_FILE, 13001); } $this->update[$child['attrs']['fromversion']] = array(); $processData =& $this->update[$child['attrs']['fromversion']]; } else { $this->install = array(); $processData =& $this->install; } foreach ($child['children'] as $instruction) { switch ($instruction['name']) { // get links to sql file case 'sql': $processData['sql'] = $instruction['cdata']; break; // get links to language files // get links to language files case 'languages': if (!isset($processData['languages'])) { $processData['languages'] = array(); } $processData['languages'][] = array('cdata' => $instruction['cdata']) + $instruction['attrs']; break; // get links to other (any but not sql) files // get links to other (any but not sql) files default: if (!isset($processData[$instruction['name']])) { $processData[$instruction['name']] = array(); } $processData[$instruction['name']][] = array('cdata' => $instruction['cdata']) + $instruction['attrs']; } } foreach ($processData as $key => $val) { if ($key != 'languages' && is_array($val) && count($val) == 1) { $processData[$key] = array_shift($val); } } 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'); } // examine the right update instruction block if ($this->package !== null && $this->update !== null) { $validUpdate = null; foreach ($this->update as $fromVersion => $update) { if (Package::checkFromversion($this->package->getVersion(), $fromVersion)) { $validUpdate = $update; break; } } $this->update = $validUpdate; } // check required tags if (!isset($this->packageInfo['packageName'])) { throw new SystemException("required tag 'packageName' is missing in " . self::INFO_FILE, 13001); } if (!isset($this->packageInfo['version'])) { throw new SystemException("required tag 'version' is missing in " . self::INFO_FILE, 13001); } // set default values if (!isset($this->packageInfo['isUnique'])) { $this->packageInfo['isUnique'] = 0; } if (!isset($this->packageInfo['standalone'])) { $this->packageInfo['standalone'] = 0; } if (!isset($this->packageInfo['plugin'])) { $this->packageInfo['plugin'] = ''; } if (!isset($this->packageInfo['packageURL'])) { $this->packageInfo['packageURL'] = ''; } // get package name in selected language $this->getLocalizedInformation('packageName'); // get package description in selected language if (isset($this->packageInfo['packageDescription'])) { $this->getLocalizedInformation('packageDescription'); } if (CHARSET != 'UTF-8') { if (isset($this->authorInfo['author'])) { $this->authorInfo['author'] = StringUtil::convertEncoding('UTF-8', CHARSET, $this->authorInfo['author']); } if (isset($this->authorInfo['authorURL'])) { $this->authorInfo['authorURL'] = StringUtil::convertEncoding('UTF-8', CHARSET, $this->authorInfo['authorURL']); } } // add plugin to requirements if ($this->packageInfo['plugin'] && !isset($this->requirements[$this->packageInfo['plugin']])) { $this->requirements[$this->packageInfo['plugin']] = array('name' => $this->packageInfo['plugin']); } }