Beispiel #1
0
 /**
  * Loads the compiled language file.
  * Compiles the language file before if necessary.
  */
 public function loadLanguage()
 {
     $filename = TMP_DIR . 'setup/lang/cache/' . $this->languageCode . '_wcf.setup.php';
     if (!file_exists($filename)) {
         $xml = new XML();
         $xml->load(TMP_DIR . 'setup/lang/setup_' . $this->languageCode . '.xml');
         // get language items
         $categoriesToCache = array();
         $items = $xml->xpath()->query('/ns:language/ns:category/ns:item');
         foreach ($items as $item) {
             $categoriesToCache[] = array('name' => $item->getAttribute('name'), 'cdata' => $item->nodeValue);
         }
         // update language files here
         if (count($categoriesToCache) > 0) {
             $file = new File($filename);
             $file->write("<?php\n/**\n* WoltLab Community Framework\n* language: " . $this->languageCode . "\n* encoding: UTF-8\n* category: WCF Setup\n* generated at " . gmdate("r") . "\n* \n* DO NOT EDIT THIS FILE\n*/\n");
             foreach ($categoriesToCache as $name) {
                 $file->write("\$this->items['" . $name['name'] . "'] = '" . str_replace("'", "\\'", $name['cdata']) . "';\n");
                 // compile dynamic language variables
                 if (strpos($name['cdata'], '{') !== false) {
                     $compiledString = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($name['name'], $name['cdata']);
                     $file->write("\$this->dynamicItems['" . $name['name'] . "'] = '" . str_replace("'", "\\'", $compiledString['template']) . "';\n");
                 }
             }
             $file->write("?>");
             $file->close();
         }
     }
     include_once $filename;
     $this->setLocale();
 }
 /**
  * @see wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // upload
     if ($this->optionImport && $this->optionImport['error'] != 4) {
         if ($this->optionImport['error'] != 0) {
             throw new UserInputException('optionImport', 'uploadFailed');
         }
         try {
             $xml = new XML($this->optionImport['tmp_name']);
             $optionsXML = $xml->getElementTree('options');
             foreach ($optionsXML['children'] as $option) {
                 $name = $value = '';
                 foreach ($option['children'] as $optionData) {
                     switch ($optionData['name']) {
                         case 'name':
                             $name = $optionData['cdata'];
                             break;
                         case 'value':
                             $value = $optionData['cdata'];
                             break;
                     }
                 }
                 if (!empty($name)) {
                     $this->options[$name] = $value;
                 }
             }
         } catch (SystemException $e) {
             throw new UserInputException('optionImport', 'importFailed');
         }
     } else {
         throw new UserInputException('optionImport');
     }
 }
 /**
  * @see wcf\system\ICronjob::execute()
  */
 public function execute(Cronjob $cronjob)
 {
     $filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
     $xml = new XML();
     $xml->load($filename);
     $xpath = $xml->xpath();
     // fetch spiders
     $spiders = $xpath->query('/spiderlist/spider');
     if (count($spiders)) {
         // delete old entries
         $sql = "DELETE FROM wcf" . WCF_N . "_spider";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
         $statementParameters = array();
         foreach ($spiders as $spider) {
             $identifier = StringUtil::toLowerCase($spider->getAttribute('ident'));
             $name = $xpath->query('name', $spider)->item(0);
             $info = $xpath->query('info', $spider)->item(0);
             $statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
         }
         if (!empty($statementParameters)) {
             $sql = "INSERT INTO\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t(?, ?, ?)";
             $statement = WCF::getDB()->prepareStatement($sql);
             foreach ($statementParameters as $parameters) {
                 $statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
             }
         }
         // clear spider cache
         CacheHandler::getInstance()->clear(WCF_DIR . 'cache', 'cache.spiders.php');
     }
     // delete tmp file
     @unlink($filename);
 }
 /**
  * @see	\wcf\system\ICronjob::execute()
  */
 public function execute(Cronjob $cronjob)
 {
     $filename = FileUtil::downloadFileFromHttp('http://assets.woltlab.com/spiderlist/typhoon/list.xml', 'spiders');
     $xml = new XML();
     $xml->load($filename);
     $xpath = $xml->xpath();
     // fetch spiders
     $spiders = $xpath->query('/ns:data/ns:spider');
     if (!empty($spiders)) {
         $existingSpiders = SpiderCacheBuilder::getInstance()->getData();
         $statementParameters = array();
         foreach ($spiders as $spider) {
             $identifier = mb_strtolower($spider->getAttribute('ident'));
             $name = $xpath->query('ns:name', $spider)->item(0);
             $info = $xpath->query('ns:url', $spider)->item(0);
             $statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
         }
         if (!empty($statementParameters)) {
             $sql = "INSERT INTO\t\t\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t\t\t(?, ?, ?)\n\t\t\t\t\tON DUPLICATE KEY UPDATE\t\tspiderName = VALUES(spiderName),\n\t\t\t\t\t\t\t\t\tspiderURL = VALUES(spiderURL)";
             $statement = WCF::getDB()->prepareStatement($sql);
             WCF::getDB()->beginTransaction();
             foreach ($statementParameters as $parameters) {
                 $statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
             }
             WCF::getDB()->commitTransaction();
         }
         // delete obsolete entries
         $sql = "DELETE FROM wcf" . WCF_N . "_spider WHERE spiderIdentifier = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($existingSpiders as $spider) {
             if (!isset($statementParameters[$spider->spiderIdentifier])) {
                 $statement->execute(array($spider->spiderIdentifier));
             }
         }
         // clear spider cache
         SpiderCacheBuilder::getInstance()->reset();
     }
     // delete tmp file
     @unlink($filename);
 }
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // upload
     if ($this->optionImport && $this->optionImport['error'] != 4) {
         if ($this->optionImport['error'] != 0) {
             throw new UserInputException('optionImport', 'uploadFailed');
         }
         try {
             $xml = new XML();
             $xml->load($this->optionImport['tmp_name']);
             $xpath = $xml->xpath();
             foreach ($xpath->query('/options/option') as $option) {
                 $this->options[$xpath->query('name', $option)->item(0)->nodeValue] = $xpath->query('value', $option)->item(0)->nodeValue;
             }
         } catch (SystemException $e) {
             throw new UserInputException('optionImport', 'importFailed');
         }
     } else {
         throw new UserInputException('optionImport');
     }
 }
 /**
  * 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);
 }
Beispiel #7
0
 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;
 }
Beispiel #8
0
 /**
  * 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;
 }
Beispiel #9
0
 /**
  * Installs the selected languages.
  */
 protected function installLanguage()
 {
     $this->initDB();
     foreach (self::$selectedLanguages as $language) {
         // get language.xml file name
         $filename = TMP_DIR . 'install/lang/' . $language . '.xml';
         // check the file
         if (!file_exists($filename)) {
             throw new SystemException("unable to find language file '" . $filename . "'");
         }
         // open the file
         $xml = new XML();
         $xml->load($filename);
         // import xml
         LanguageEditor::importFromXML($xml, 0);
     }
     // set default language
     $language = LanguageFactory::getInstance()->getLanguageByCode(in_array(self::$selectedLanguageCode, self::$selectedLanguages) ? self::$selectedLanguageCode : self::$selectedLanguages[0]);
     LanguageFactory::getInstance()->makeDefault($language->languageID);
     // assign all languages to package id 0
     $sql = "SELECT\tlanguageID\n\t\t\tFROM\twcf" . WCF_N . "_language";
     $statement = self::getDB()->prepareStatement($sql);
     $statement->execute();
     $languages = array();
     while ($row = $statement->fetchArray()) {
         $languages[] = $row['languageID'];
     }
     if (count($languages) > 0) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_language_to_package\n\t\t\t\t\t\t(languageID)\n\t\t\t\tVALUES\t\t(?)";
         $statement = self::getDB()->prepareStatement($sql);
         foreach ($languages as $languageID) {
             $statement->execute(array($languageID));
         }
     }
     // rebuild language cache
     CacheHandler::getInstance()->clearResource('languages');
     // go to next step
     $this->gotoNextStep('createUser');
 }
Beispiel #10
0
 /**
  * Installs the selected languages.
  */
 protected function installLanguage()
 {
     $this->initDB();
     foreach (self::$selectedLanguages as $language) {
         // get language.xml file name
         $filename = TMP_DIR . 'install/lang/' . $language . '.xml';
         // check the file
         if (!file_exists($filename)) {
             throw new SystemException("unable to find language file '" . $filename . "'");
         }
         // open the file
         $xml = new XML();
         $xml->load($filename);
         // import xml
         LanguageEditor::importFromXML($xml, 0);
     }
     // set default language
     $language = LanguageFactory::getInstance()->getLanguageByCode(in_array(self::$selectedLanguageCode, self::$selectedLanguages) ? self::$selectedLanguageCode : self::$selectedLanguages[0]);
     LanguageFactory::getInstance()->makeDefault($language->languageID);
     // rebuild language cache
     LanguageCacheBuilder::getInstance()->reset();
     // go to next step
     $this->gotoNextStep('createUser');
 }
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // check file
     if (!file_exists($this->filename)) {
         throw new UserInputException('languageFile');
     }
     // try to import
     try {
         // open xml document
         $xml = new XML();
         $xml->load($this->filename);
         // import xml document
         $this->language = LanguageEditor::importFromXML($xml, -1);
     } catch (SystemException $e) {
         throw new UserInputException($this->importField, $e->getMessage());
     }
 }
Beispiel #12
0
 /**
  * Reads the data of a variables.xml file.
  * 
  * @param	string		$string		contents of a variable.xml file
  * @return	array		data
  */
 public static function readVariablesData($string)
 {
     // open variables.xml
     $variablesXML = new XML();
     $variablesXML->loadString($string);
     $variablesXMLContent = $variablesXML->getElementTree('variables');
     // get variables
     $variables = array();
     foreach ($variablesXMLContent['children'] as $variable) {
         if (isset($variable['attrs']['name'])) {
             $variables[$variable['attrs']['name']] = $variable['cdata'];
         }
     }
     return $variables;
 }
Beispiel #13
0
	/**
	 * 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'] = '';
	}
 /**
  * Takes an XML object and returns the specific country code.
  * 
  * @param	\wcf\util\XML	$xml
  * @return	string		country code
  */
 public static function readCountryCodeFromXML(XML $xml)
 {
     $rootNode = $xml->xpath()->query('/ns:language')->item(0);
     $attributes = $xml->xpath()->query('attribute::*', $rootNode);
     foreach ($attributes as $attribute) {
         if ($attribute->name == 'countrycode') {
             return $attribute->value;
         }
     }
     throw new SystemException("missing attribute 'countrycode' in language file");
 }
 /**
  * Loads the xml file into a string and returns this string.
  *
  * @param	string		$filename
  * @return 	XML		$xml
  */
 protected function getXML($filename = '')
 {
     if (empty($filename)) {
         $filename = $this->instruction['value'];
     }
     // Search the xml-file in the package archive.
     // Abort installation in case no file was found.
     if (($fileIndex = $this->installation->getArchive()->getTar()->getIndexByFilename($filename)) === false) {
         throw new SystemException("xml file '" . $filename . "' not found in '" . $this->installation->getArchive()->getArchive() . "'");
     }
     // Extract acpmenu file and parse with SimpleXML
     $xml = new XML();
     $tmpFile = FileUtil::getTemporaryFilename('xml_');
     try {
         $this->installation->getArchive()->getTar()->extract($fileIndex, $tmpFile);
         $xml->load($tmpFile);
     } catch (\Exception $e) {
         // bugfix to avoid file caching problems
         try {
             $this->installation->getArchive()->getTar()->extract($fileIndex, $tmpFile);
             $xml->load($tmpFile);
         } catch (\Exception $e) {
             $this->installation->getArchive()->getTar()->extract($fileIndex, $tmpFile);
             $xml->load($tmpFile);
         }
     }
     @unlink($tmpFile);
     return $xml;
 }
 /**
  * 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 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;
 }
 /**
  * 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;
 }
Beispiel #19
0
	/**
	 * @see	wcf\form\Form::validate()
	 */
	public function validate() {
		parent::validate();
		
		if ($this->mode == 'copy') {
			// language code
			if (empty($this->languageCode)) {
				throw new UserInputException('languageCode');
			}
			
			// 
			if (LanguageFactory::getInstance()->getLanguageByCode($this->languageCode)) {
				throw new UserInputException('languageCode', 'notUnique');
			}
			
			// source language id
			if (empty($this->sourceLanguageID)) {
				throw new UserInputException('sourceLanguageID');
			}
			
			// get language
			$this->sourceLanguage = LanguageFactory::getInstance()->getLanguage($this->sourceLanguageID);
			if (!$this->sourceLanguage->languageID) {
				throw new UserInputException('sourceLanguageID');
			}
		}
		else {
			// check file
			if (!file_exists($this->filename)) {
				throw new UserInputException('languageFile');
			}
			
			// try to import
			try {
				// open xml document
				$xml = new XML();
				$xml->load($this->filename);
				
				// import xml document
				$this->language = LanguageEditor::importFromXML($xml, PACKAGE_ID);
			}
			catch (SystemException $e) {
				throw new UserInputException($this->importField, $e->getMessage());
			}
		}
	}