本文整理汇总了PHP中XML::loadString方法的典型用法代码示例。如果您正苦于以下问题:PHP XML::loadString方法的具体用法?PHP XML::loadString怎么用?PHP XML::loadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML::loadString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ls
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('');
}
示例2: easyUpdateItems
/**
* 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);
}
示例3: createPermissions
/**
* 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);
}
}
示例4: header
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);
}
示例5: parsePackageUpdateXML
/**
* 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;
}
示例6: readVariablesData
/**
* 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;
}
示例7: readLanguage
/**
* 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;
}
示例8: readPackageInfo
/**
* 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'])) {
//.........这里部分代码省略.........
示例9: call
/**
* @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;
}