public static function ls($url, array $loginDetails = array(), array $options = array()) { $options['asXML'] = true; $output = self::executeCommand('list', $url, $loginDetails, $options); $output = implode($output, ''); $xml = new XML(); $xml->loadString($output); return $xml->getElementTree(''); }
/** * Updates the language items of a language category. * * @param array $items * @param integer $categoryID * @param integer $packageID * @param array $useCustom */ public function easyUpdateItems($categoryString, $items, $packageID = null) { $packageID = $packageID === null ? WCF::getPackageID('de.easy-coding.wcf.contest') : $packageID; $language = new LanguageEditor($this->languageID); $xmlString = '<?xml version="1.0" encoding="' . CHARSET . '"?> <language languagecode="' . $this->getLanguageCode() . '"> <category name="' . $categoryString . '">'; foreach ($items as $key => $val) { if ($val === null) { continue; } $xmlString .= '<item name="' . $key . '"><![CDATA[' . $val . ']]></item>'; } $xmlString .= ' </category> </language>'; $xml = new XML(); $xml->loadString($xmlString); $language->updateFromXML($xml, $packageID); }
/** * Creates permissions for this source */ public function createPermissions() { // determine position for next group option $sql = "SELECT\tIFNULL(MAX(showOrder), 0) + 1 AS showOrder\n\t\t\tFROM\twcf" . WCF_N . "_group_option\n\t\t\tWHERE\tcategoryName = 'user.source.dynamic'\n\t\t\tAND\tpackageID = " . PACKAGE_ID; $row = WCF::getDB()->getFirstRow($sql); $showOrder = $row['showOrder']; // create group option $sql = "INSERT INTO\twcf" . WCF_N . "_group_option\n\t\t\t\t\t(packageID, optionName, categoryName, optionType, defaultValue, showOrder, validationPattern, enableOptions, permissions, options, additionalData)\n\t\t\tVALUES\t\t(" . PACKAGE_ID . ",\n\t\t\t\t\t'user.source.dynamic.canUseSource" . $this->sourceID . "',\n\t\t\t\t\t'user.source.dynamic',\n\t\t\t\t\t'boolean',\n\t\t\t\t\t0,\n\t\t\t\t\t" . intval($showOrder) . ",\n\t\t\t\t\t'',\n\t\t\t\t\t'',\n\t\t\t\t\t'',\n\t\t\t\t\t'',\n\t\t\t\t\t'" . serialize(array()) . "')"; WCF::getDB()->sendQuery($sql); $optionID = WCF::getDB()->getInsertID(); // insert new option and default value to each group // get all groupIDs // don't change values of existing options $sql = "SELECT\tgroupID\n\t\t\tFROM\twcf" . WCF_N . "_group"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_group_option_value\n\t\t\t\t\t\t\t(groupID, optionID, optionValue)\n\t\t\t\tVALUES\t\t\t(" . $row['groupID'] . ",\n\t\t\t\t\t\t\t " . $optionID . ",\n\t\t\t\t\t\t\t'0')"; WCF::getDB()->sendQuery($sql); } WCF::getCache()->clear(WCF_DIR . 'cache/', 'cache.group-option-*.php'); // get available languages $languageCodes = Language::getLanguageCodes(); // create language variables $sql = "SELECT\tlanguageID, languageItem, languageItemValue\n\t\t\tFROM\twcf" . WCF_N . "_language_item\n\t\t\tWHERE\tlanguageItem IN\n\t\t\t\t(\n\t\t\t\t\t'wcf.acp.group.option.user.source.dynamic.default',\n\t\t\t\t\t'wcf.acp.group.option.user.source.dynamic.default.description'\n\t\t\t\t)\n\t\t\tAND\tpackageID = " . PACKAGE_ID; $result = WCF::getDB()->sendQuery($sql); $languageData = array(); // create language variables for each language while ($row = WCF::getDB()->fetchArray($result)) { $key = 'option.user.source.dynamic.canUseSource' . $this->sourceID; if ($row['languageItem'] == 'wcf.acp.group.option.user.source.dynamic.default.description') { $key .= '.description'; } $value = str_replace('#sourceName#', $this->name, $row['languageItemValue']); $languageCode = $languageCodes[$row['languageID']]; $languageData[$languageCode]['wcf.acp.group'][$key] = $value; } // import language variables foreach ($languageData as $languageCode => $data) { //create XML string $xml = LanguagesXMLPIP::create(array($languageCode => $data), true); // parse xml $xmlObj = new XML(); $xmlObj->loadString($xml); // import language xml LanguageEditor::importFromXML($xmlObj, PACKAGE_ID); } }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with WOT Game. If not, see <http://www.gnu.org/licenses/>. */ define('INSIDE', true); $ugamela_root_path = '../'; include $ugamela_root_path . 'extension.inc'; include $ugamela_root_path . 'common.' . $phpEx; if (!check_user()) { header("Location: login.php"); die; } require_once WCF_DIR . 'lib/system/language/LanguageEditor.class.php'; require_once WCF_DIR . 'lib/util/XML.class.php'; $std = 'english'; $languages = WCF::getCache()->get('languages'); foreach ($languages as $languageID => $languageArray) { $editor = new LanguageEditor($languageID); if (file_exists('lang/' . $languageArray['languageCode'] . '.xml')) { $xml = new XML('lang/' . $languageArray['languageCode'] . '.xml'); } else { $string = file_get_contents('lang/' . $std . '.xml'); $string = preg_replace('/languagecode="' . $std . '"/i', 'languagecode="' . $std . '"', $string, 1); $xml = new XML(); $xml->loadString($string); } $editor->updateFromXML($xml); }
/** * 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; }
/** * 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; }
/** * Extracts the language file and parses it with * SimpleXML. If the specified language file * was not found, an error message is thrown. * * @param string $language * @return XML xml */ protected function readLanguage($language) { // No <language>-tag in the instructions in package.xml if (!isset($language['cdata']) || !$language['cdata']) { return false; } // search language files in package archive // throw error message if not found if (($fileIndex = $this->installation->getArchive()->getTar()->getIndexByFilename($language['cdata'])) === false) { throw new SystemException("language file '" . $language['cdata'] . "' not found.", 13025); } // extract language file and parse with SimpleXML $xml = new XML(); $xml->loadString($this->installation->getArchive()->getTar()->extractToString($fileIndex)); return $xml; }
/** * 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']); } }
/** * @param string * @param array (string key => mixed value, ...) * @param string "POST"|"GET" * @return array XML DOM * @throws HTTPException * @throws XMLParserException */ public function call($url, $params = null, $method = 'GET') { if ($params && is_array($params)) { $vv = array(); foreach ($params as $k => $v) { if (is_array($v)) { foreach ($v as $v2) { $vv[] = rawurlencode($k) . '=' . rawurlencode($v2); } } else { $vv[] = rawurlencode($k) . '=' . rawurlencode($v); } } $params = implode('&', $vv); } else { $params = ''; } $conn = new HTTPConnection(strval($url)); $conn->method = $method; $conn->curlOptions[CURLOPT_USERAGENT] = 'RESTService $Id$'; $conn->curlOptions[CURLOPT_CONNECTTIMEOUT] = 10; # short connect timeout if ($method != 'POST' && $params) { $conn->url .= '?' . $params; $params = null; } if ($this->debug) { print 'DEBUG>> RESTService->call(' . $service_id . ':' . $name . '): ' . ($conn->method == 'POST' ? 'POST' : 'GET') . ' ' . $conn->url . "<br/>\n"; if ($conn->method == 'POST') { print 'DEBUG>> POST data: ' . var_export($params, 1) . "\n<br/>"; } } # Send request $data = $conn->connect($params); if ($this->debug) { print 'DEBUG>> RESTService->call(' . $service_id . ':' . $name . '): Response: HTTP/' . $conn->responseProtocol . ' ' . $conn->responseStatus . "<br/>\n{$data}\n<br/>"; } # Parse response $data = XML::loadString($data); # Handle response errors if (substr(strval($conn->responseStatus), 0, 1) != '2') { throw new HTTPException($conn->responseStatusName, $conn->responseStatus); } return $data; }