/** * 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\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'); } }
/** * 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; }
/** * 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'); }
/** * 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'); }
/** * @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()); } }
/** * @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()); } } }