public function responseMsg() { //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if (!empty($postStr)) { /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $textTpl = "<xml>\n\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t\t</xml>"; if (!empty($keyword)) { $msgType = "text"; $contentStr = "Welcome to wechat world!"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } else { echo "Input something..."; } } else { echo ""; exit; } }
public static function toXml($data, $rootNodeName = 'data', $xml = null) { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if ($xml == null) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />"); } // loop through the data passed in. foreach ($data as $key => $value) { // no numeric keys in our xml please! if (is_numeric($key)) { // make string key... $key = "child_" . (string) $key; } // replace anything not alpha numeric $key = preg_replace('/[^a-z]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { $node = $xml->addChild($key); // recrusive call. ArrayToXML::toXml($value, $rootNodeName, $node); } else { // add single node. $value = htmlentities($value); $xml->addChild($key, $value); } } // pass back as string. or simple xml object if you want! return $xml->asXML(); }
/** * 解析从ListMultipartUpload接口的返回数据 * * @return ListMultipartUploadInfo */ protected function parseDataFromResponse() { $content = $this->rawResponse->body; $xml = simplexml_load_string($content); $encodingType = isset($xml->EncodingType) ? strval($xml->EncodingType) : ""; $bucket = isset($xml->Bucket) ? strval($xml->Bucket) : ""; $keyMarker = isset($xml->KeyMarker) ? strval($xml->KeyMarker) : ""; $keyMarker = OssUtil::decodeKey($keyMarker, $encodingType); $uploadIdMarker = isset($xml->UploadIdMarker) ? strval($xml->UploadIdMarker) : ""; $nextKeyMarker = isset($xml->NextKeyMarker) ? strval($xml->NextKeyMarker) : ""; $nextKeyMarker = OssUtil::decodeKey($nextKeyMarker, $encodingType); $nextUploadIdMarker = isset($xml->NextUploadIdMarker) ? strval($xml->NextUploadIdMarker) : ""; $delimiter = isset($xml->Delimiter) ? strval($xml->Delimiter) : ""; $delimiter = OssUtil::decodeKey($delimiter, $encodingType); $prefix = isset($xml->Prefix) ? strval($xml->Prefix) : ""; $prefix = OssUtil::decodeKey($prefix, $encodingType); $maxUploads = isset($xml->MaxUploads) ? intval($xml->MaxUploads) : 0; $isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : ""; $listUpload = array(); if (isset($xml->Upload)) { foreach ($xml->Upload as $upload) { $key = isset($upload->Key) ? strval($upload->Key) : ""; $key = OssUtil::decodeKey($key, $encodingType); $uploadId = isset($upload->UploadId) ? strval($upload->UploadId) : ""; $initiated = isset($upload->Initiated) ? strval($upload->Initiated) : ""; $listUpload[] = new UploadInfo($key, $uploadId, $initiated); } } return new ListMultipartUploadInfo($bucket, $keyMarker, $uploadIdMarker, $nextKeyMarker, $nextUploadIdMarker, $delimiter, $prefix, $maxUploads, $isTruncated, $listUpload); }
private function start($parser, $name, $attrs) { $name = str_replace(':', '', $name); if ($this->depth == 1) { $this->node = $this->handler = simplexml_load_string("<{$name}></{$name}>", 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE); } elseif ($this->depth > 1) { if ($this->raw != false) { $this->handler[0] .= '<' . $name . ' '; if ($this->raw <= $this->depth) { foreach ($attrs as $name => $value) { $this->handler[0] .= $name . "='" . $value . "' "; } } $this->handler[0] .= '>'; } else { $this->handler = $this->handler->addChild($name); } } if (isset($this->handler) && $this->raw == false) { foreach ($attrs as $name => $value) { if ('xmlns:' === substr($name, 0, 6)) { $name = 'xmlns:' . $name; } if ($value === 'http://www.w3.org/1999/xhtml') { $this->raw = $this->depth; } $this->handler->addAttribute($name, $value); } } $this->depth++; }
/** * Returns array of simple xml objects, where key is a handle name * * @return SimpleXmlElement[] * @throws RuntimeException in case of load error (malformed xml, etc) */ public function load() { $this->validate(); $original = libxml_use_internal_errors(true); $simpleXmlElement = simplexml_load_file($this->filePath); $errors = libxml_get_errors(); libxml_clear_errors(); libxml_use_internal_errors($original); if ($simpleXmlElement === false) { $messages = array(); foreach ($errors as $error) { $messages[] = sprintf('%s, line %s, column %s', trim($error->message), $error->line, $error->column); } throw new RuntimeException(sprintf('File "%s" has a malformed xml structure: %s', $this->filePath, PHP_EOL . implode(PHP_EOL, $messages))); } $stringXml = array(); // First convert all elements to string, // as in xml file can be multiple string with the same handle names foreach ($simpleXmlElement->children() as $key => $element) { if (!isset($stringXml[$key])) { $stringXml[$key] = ''; } foreach ($element->children() as $child) { $stringXml[$key] .= $child->asXml(); } } $result = array(); foreach ($stringXml as $key => $xml) { $result[$key] = simplexml_load_string(sprintf('<%1$s>%2$s</%1$s>', $key, $xml)); } return $result; }
public function testXmlValidates() { $f = new XmlFormatter(); $line = $f->format(array('message' => 'foo', 'priority' => 42)); $sxml = @simplexml_load_string($line); $this->assertInstanceOf('SimpleXMLElement', $sxml, 'Formatted XML is invalid'); }
/** * Check the given xml * * @param string $xml * * @return null * * @throws InvalidXmlException */ public function checkXml($xml) { $output = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOERROR); if (false === $output) { throw new InvalidXMLException(); } }
private function __construct($objectId, $mySide) { $this->mySide = $mySide; $this->object = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $objectId); if (!$this->object || !$this->object instanceof \steam_container) { throw new Exception("Wave side not found."); } //$controlObject = \steam_factory::get_object_by_name($GLOBALS["STEAM"]->get_id(), $this->object->get_path() . "/control.xml"); if (isset($controlObject) && $controlObject instanceof \steam_document) { $xmlStr = $controlObject->get_content(); $xml = simplexml_load_string($xmlStr); $children = $xml->children(); foreach ($children as $child) { if ($child->getName() == "OBJ_DESC") { $this->object->set_attribute(OBJ_DESC, $child->asXML()); } else { if ($child->getName() == "steamweb_type") { $this->object->set_attribute("WAVEPAGE_TYPE", $child->asXML()); } else { if ($child->getName() == "steamweb_type_config") { $subChildren = $child->children(); $map = XmlHelper::xml_to_array($subChildren[0]); $this->object->set_attribute("WAVEPAGE_TYPE_CONFIG", $map[0]); } else { if ($child->getName() == "steamweb_module_ssp") { $subChildren = $child->children(); $this->object->set_attribute("WAVEPAGE_MODULE_SSP_ALBUM_NO", $subChildren[0]->asXML()); } } } } } } }
/** * Returns an instance of KeyInfo object based on the input KeyInfo XML block * * @param string $xmlData The KeyInfo XML Block * @return Zend_InfoCard_Xml_KeyInfo_Abstract * @throws Zend_InfoCard_Xml_Exception */ public static function getInstance($xmlData) { if ($xmlData instanceof Zend_InfoCard_Xml_Element) { $strXmlData = $xmlData->asXML(); } else { if (is_string($xmlData)) { $strXmlData = $xmlData; } else { throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance"); } } $sxe = simplexml_load_string($strXmlData); $namespaces = $sxe->getDocNameSpaces(); if (!empty($namespaces)) { foreach ($sxe->getDocNameSpaces() as $namespace) { switch ($namespace) { case 'http://www.w3.org/2000/09/xmldsig#': include_once 'Zend/InfoCard/Xml/KeyInfo/XmlDSig.php'; return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_XmlDSig'); default: throw new Zend_InfoCard_Xml_Exception("Unknown KeyInfo Namespace provided"); // We are ignoring these lines, as XDebug reports each as a "non executed" line // which breaks my coverage % // @codeCoverageIgnoreStart } } } // @codeCoverageIgnoreEnd include_once 'Zend/InfoCard/Xml/KeyInfo/Default.php'; return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_Default'); }
public function browse($source, $from) { $source = strtolower($source); $index = $this->config[$source]['id']; $bases = $this->config['Global']['bases']; $removeRegex = $this->config[$source]['search_remove']; if (isset($removeRegex)) { $from = preg_replace($removeRegex, '', $from); } $params = array('index' => $index, 'query' => $from, 'base' => $bases); $answer = $this->httpService->get($this->cgiUrl, $params); $xml = simplexml_load_string($answer->getBody()); $indexes = array(); $count = 0; $next = null; foreach ($xml->{'result'} as $result) { $ids = array(); foreach ($result->id as $id) { $ids[] = (string) $id; } $heading = $this->getDisplayText($source, (string) $result->display); if ($count < 10) { $indexes[] = array('heading' => $heading, 'ids' => $ids, 'count' => count($ids)); } else { $next = (string) $result->sort; } $count++; } $result = array('items' => $indexes); if (isset($next)) { $result['nextQuery'] = array('source' => $source, 'from' => $next); } return $result; }
protected function getItemData($item_id, $lang, $itemname = '', $type = 'items') { if ($item_id < 1) { return null; } $xml_link = 'http://lotro.allakhazam.com/cluster/item-xml.pl?lotritem=' . $item_id; $xml_data = $this->puf->fetch($xml_link); $xml = simplexml_load_string($xml_data); //filter baditems if (!isset($xml->display_html) or strlen($xml->display_html) < 5) { $item['baditem'] = true; return $item; } $item['link'] = 'http://lotro.allakhazam.com/db/item.html?lotritem=' . $item_id; $item['id'] = 0; # dont store this id, since its an allkhazam internal id $item['name'] = (string) $xml->item_name; $item['icon'] = (string) $xml->icon; $item['lang'] = $lang; $item['color'] = 'item' . $xml->quality; $item['html'] = (string) $xml->display_html; $item['html'] = $item['html']; //reposition allakhazam-credit-stuff $alla_credit = '<br><span class="akznotice">Item display is courtesy <a href="http://lotro.allakhazam.com/">lotro.allakhazam.com</a>.</span>'; $item['html'] = str_replace($alla_credit, "", $item['html']) . $alla_credit; $item['html'] = str_replace('{ITEM_HTML}', $item['html'], file_get_contents($this->root_path . 'games/lotro/infotooltip/templates/lotro_popup.tpl')); return $item; }
public function testNormalizeArray() { $client = new Client($this->getConfig()); $rfl = new \ReflectionClass($client); $method = $rfl->getMethod('normalizeArray'); $method->setAccessible(true); $xml = <<<EOF <?xml version="1.0"?> <root> <key>value</key> <empty></empty> <recursive> <key>value</key> <empty></empty> </recursive> <list> <item> <key>value</key> </item> <item> <key>value</key> </item> </list> </root> EOF; $array = (array) simplexml_load_string($xml); $array = $method->invoke($client, $array); $this->assertTrue(is_array($array)); $this->assertCount(4, $array); $this->assertArrayHasKey('key', $array); $this->assertArrayHasKey('empty', $array); $this->assertArrayHasKey('recursive', $array); $this->assertArrayHasKey('list', $array); $this->assertSame('value', $array['key']); $this->assertNull($array['empty']); $this->assertTrue(is_array($array['recursive'])); $this->assertTrue(is_array($array['list'])); $this->assertFalse($array['recursive'] instanceof \SimpleXMLElement); $this->assertFalse($array['list'] instanceof \SimpleXMLElement); $recursive = $array['recursive']; $this->assertCount(2, $recursive); $this->assertArrayHasKey('key', $recursive); $this->assertArrayHasKey('empty', $recursive); $this->assertSame('value', $recursive['key']); $this->assertNull($recursive['empty']); $list = $array['list']; $this->assertCount(1, $list); $this->assertArrayHasKey('item', $list); $this->assertTrue(is_array($list['item'])); $this->assertFalse($list['item'] instanceof \SimpleXMLElement); $this->assertCount(2, $list['item']); $this->assertArrayHasKey(0, $list['item']); $this->assertArrayHasKey(1, $list['item']); $this->assertTrue(is_array($list['item'][0])); $this->assertTrue(is_array($list['item'][1])); $this->assertArrayHasKey('key', $list['item'][0]); $this->assertArrayHasKey('key', $list['item'][1]); $this->assertSame('value', $list['item'][0]['key']); $this->assertSame('value', $list['item'][1]['key']); }
/** * Test the JFormRuleTel::test method. */ public function testTel() { $rule = new JFormRuleTel(); $xml = simplexml_load_string('<form><field name="tel1" plan="NANP" /> <field name="tel2" plan="ITU-T" /><field name="tel3" plan="EPP" /> <field name="tel4" /></form>'); // Test fail conditions NANP. $this->assertThat($rule->test($xml->field[0], 'bogus'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[0], '123451234512'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[0], 'anything_5555555555'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[0], '5555555555_anything'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); // Test fail conditions ITU-T. $this->assertThat($rule->test($xml->field[1], 'bogus'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[1], '123451234512'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[1], 'anything_5555555555'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[1], '5555555555_anything'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[1], '1 2 3 4 5 6 '), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[1], '5552345678'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[1], 'anything_555.5555555'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[1], '555.5555555_anything'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); // Test fail conditions EPP. $this->assertThat($rule->test($xml->field[2], 'bogus'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[2], '12345123451234512345'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[2], '123.1234'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[2], '23.1234'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[2], '3.1234'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); // Test fail conditions no plan. $this->assertThat($rule->test($xml->field[3], 'bogus'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[3], 'anything_555.5555555'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[3], '555.5555555x555_anything'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[3], '.5555555'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[3], '555.'), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); $this->assertThat($rule->test($xml->field[3], '1 2 3 4 5 6 '), $this->isFalse(), 'Line:' . __LINE__ . ' The rule should fail and return false.'); // Test pass conditions. //For NANP $this->assertThat($rule->test($xml->field[0], '(555) 234-5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[0], '1-555-234-5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[0], '+1-555-234-5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[0], '555-234-5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[0], '1-555-234-5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[0], '1 555 234 5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); //For ITU-T $this->assertThat($rule->test($xml->field[1], '+555 234 5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[1], '+123 555 234 5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[1], '+2 52 34 55'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[1], '+5552345678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); //For EPP $this->assertThat($rule->test($xml->field[2], '+123.1234'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[2], '+23.1234'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[2], '+3.1234'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[2], '+3.1234x555'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); //For no plan $this->assertThat($rule->test($xml->field[3], '555 234 5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[3], '+123 555 234 5678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[3], '+2 52 34 55'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[3], '5552345678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[3], '+5552345678'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[3], '1 2 3 4 5 6 7'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); $this->assertThat($rule->test($xml->field[3], '123451234512'), $this->isTrue(), 'Line:' . __LINE__ . ' The rule should pass and return true.'); }
function create_data() { $svg_file = find_file($this->paths['tempdir'], '.svg'); $return = array(); if (empty($svg_file)) { zn_delete_folder($this->paths['tempdir']); $return['message'] = 'The zip did not contained any svg files.'; } $file_data = file_get_contents(trailingslashit($this->paths['tempdir']) . $svg_file); if (!is_wp_error($file_data) && !empty($file_data)) { $xml = simplexml_load_string($file_data); $font_attr = $xml->defs->font->attributes(); $this->font_name = (string) $font_attr['id']; $icon_list = array(); $glyphs = $xml->defs->font->children(); $class = ''; foreach ($glyphs as $item => $glyph) { if ($item == 'glyph') { $attributes = $glyph->attributes(); $unicode = (string) $attributes['unicode']; $d = (string) $attributes['d']; if ($class != 'hidden' && !empty($d)) { $unicode_key = trim(json_encode($unicode), '\\\\"'); if ($item == 'glyph' && !empty($unicode_key) && trim($unicode_key) != '') { $icon_list[$this->font_name][$unicode_key] = $unicode_key; } } } } if (!empty($icon_list) && !empty($this->font_name)) { $icon_list_file = fopen($this->paths['tempdir'] . '/icon_list.php', 'w'); if ($icon_list_file) { fwrite($icon_list_file, '<?php $icons = array();'); foreach ($icon_list[$this->font_name] as $unicode) { if (!empty($unicode)) { $delimiter = "'"; if (strpos($unicode, "'") !== false) { $delimiter = '"'; } fwrite($icon_list_file, "\r\n" . '$icons[\'' . $this->font_name . '\'][' . $delimiter . $unicode . $delimiter . '] = ' . $delimiter . $unicode . $delimiter . ';'); } } fclose($icon_list_file); } else { zn_delete_folder($this->paths['tempdir']); $return['message'] = 'There was a problem creating the icon list file'; return; } // RENAME ALL FILES SO WE CAN LOAD THEM BY FONT NAME $this->rename_files(); // RENAME THE FOLDER WITH THE FONT NAME $this->rename_folder(); // ADD FONT DATA TO FONT OPTION $this->add_font_data(); } } else { $return['message'] = 'The svg file could not be opened.'; } return $return; }
/** * Formats the response based on the set response_type * * @param array $response * @return array */ protected function handleResponse($response) { if ($this->response_type === 'json') { return json_decode($response->getBody(), true); } return simplexml_load_string($response->getBody()); }
/** * Method to create an RSS feed object * * @param mixed $options * @param int $limit * @throws Exception * @return \Pop\Feed\Format\Rss */ public function __construct($options, $limit = 0) { parent::__construct($options, $limit); // Create the SimpleXMLElement if (null === $this->obj) { if (!($this->obj = simplexml_load_string($this->source, 'SimpleXMLElement', LIBXML_NOWARNING))) { throw new Exception('That feed URL cannot be read at this time. Please try again later.'); } } // Check for the date if (isset($this->obj->channel->lastBuildDate)) { $date = (string) $this->obj->channel->lastBuildDate; } else { if (isset($this->obj->channel->pubDate)) { $date = (string) $this->obj->channel->pubDate; } else { $date = null; } } // Get the main header info of the feed $feed = array(); $feed['title'] = isset($this->obj->channel->title) ? (string) $this->obj->channel->title : null; $feed['url'] = isset($this->obj->channel->link) ? (string) (string) $this->obj->channel->link : null; $feed['description'] = isset($this->obj->channel->description) ? (string) $this->obj->channel->description : null; $feed['date'] = $date; $feed['generator'] = isset($this->obj->channel->generator) ? (string) $this->obj->channel->generator : null; $feed['author'] = isset($this->obj->channel->managingEditor) ? (string) $this->obj->channel->managingEditor : null; $feed['items'] = array(); $this->feed = new \ArrayObject($feed, \ArrayObject::ARRAY_AS_PROPS); }
/** * Image List XML Parser * * @param string $xml Xml file * @param string $data dataId to read * @return $total */ function traer_info($xml, $data) { if (!strrpos("__" . $xml, "http")) { $sx = simplexml_load_file($xml); } else { $content = file_get_contents($xml); $sx = simplexml_load_string($content); } foreach ($sx->data as $item) { if ($data == $item->dataId) { $headerImageFile = $item->imageFile; foreach ($item->list->listItem as $item2) { $text[] = $item2->text; $nextLevelLevelId[] = $item2->nextLevel->nextLevelLevelId; $nextLevelDataId[] = $item2->nextLevel->nextLevelDataId; } } } $total[0] = $headerImageFile; if (isset($item->list->listItem)) { $total[1] = $text; $total[2] = $nextLevelLevelId; $total[3] = $nextLevelDataId; } return $total; }
/** * Test autosaving a post * @return void */ public function test_autosave_post() { // Become an admin $this->_setRole( 'administrator' ); // Set up the $_POST request $md5 = md5( uniqid() ); $_POST = array( 'post_id' => $this->_post->ID, 'autosavenonce' => wp_create_nonce( 'autosave' ), 'post_content' => $this->_post->post_content . PHP_EOL . $md5, 'post_type' => 'post', 'autosave' => 1, ); // Make the request try { $this->_handleAjax( 'autosave' ); } catch ( WPAjaxDieContinueException $e ) { unset( $e ); } // Get the response $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); // Ensure everything is correct $this->assertEquals( $this->_post->ID, (int) $xml->response[0]->autosave['id'] ); $this->assertEquals( 'autosave_' . $this->_post->ID, (string) $xml->response['action']); // Check that the edit happened $post = get_post( $this->_post->ID) ; $this->assertGreaterThanOrEqual( 0, strpos( $post->post_content, $md5 ) ); }
/** * Retrieves the XML geocode address lookup. * ! Results of this method are cached for 1 day. * * @param string $address adress * @return object SimpleXML */ public static function address_to_xml($address) { static $cache; // Load Cache if ($cache === NULL) { $cache = Cache::instance(); } // Address cache key $key = 'gmap-address-' . sha1($address); if ($xml = $cache->get($key)) { // Return the cached XML return simplexml_load_string($xml); } else { // Set the XML URL $xml = Gmap::api_url('maps/geo', array('output' => 'xml', 'q' => $address), '&'); // Disable error reporting while fetching the feed $ER = error_reporting(~E_NOTICE); // Load the XML $xml = simplexml_load_file($xml); if (is_object($xml) and $xml instanceof SimpleXMLElement and (int) $xml->Response->Status->code === 200) { // Cache the XML $cache->set($key, $xml->asXML(), array('gmaps'), 86400); } else { // Invalid XML response $xml = FALSE; } // Turn error reporting back on error_reporting($ER); } return $xml; }
public function loadLocalisationPack($file, $selection, $install_mode = false, $iso_localization_pack = null) { if (!($xml = @simplexml_load_string($file))) { return false; } libxml_clear_errors(); $main_attributes = $xml->attributes(); $this->name = (string) $main_attributes['name']; $this->version = (string) $main_attributes['version']; if ($iso_localization_pack) { $id_country = (int) Country::getByIso($iso_localization_pack); if ($id_country) { $country = new Country($id_country); } if (!$id_country || !Validate::isLoadedObject($country)) { $this->_errors[] = Tools::displayError(sprintf('Cannot load country : %1d', $id_country)); return false; } if (!$country->active) { $country->active = 1; if (!$country->update()) { $this->_errors[] = Tools::displayError(sprintf('Cannot enable the associated country: %1s', $country->name)); } } } $res = true; if (empty($selection)) { $res &= $this->_installStates($xml); $res &= $this->_installTaxes($xml); $res &= $this->_installCurrencies($xml, $install_mode); $res &= $this->installConfiguration($xml); $res &= $this->installModules($xml); $res &= $this->updateDefaultGroupDisplayMethod($xml); if (($res || $install_mode) && isset($this->iso_code_lang)) { if (!($id_lang = (int) Language::getIdByIso($this->iso_code_lang, true))) { $id_lang = 1; } if (!$install_mode) { Configuration::updateValue('PS_LANG_DEFAULT', $id_lang); } } elseif (!isset($this->iso_code_lang) && $install_mode) { $id_lang = 1; } if (!Language::isInstalled(Language::getIsoById($id_lang))) { $res &= $this->_installLanguages($xml, $install_mode); $res &= $this->_installUnits($xml); } if ($install_mode && $res && isset($this->iso_currency)) { Cache::clean('Currency::getIdByIsoCode_*'); $res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int) Currency::getIdByIsoCode($this->iso_currency)); Currency::refreshCurrencies(); } } else { foreach ($selection as $selected) { // No need to specify the install_mode because if the selection mode is used, then it's not the install $res &= Validate::isLocalizationPackSelection($selected) ? $this->{'_install' . $selected}($xml) : false; } } return $res; }
public function read($data) { msAPI::log('[' . strtoupper($this->handler) . '] Reading data into readable array supported by all formats'); switch ($this->handler) { case 'json': if (!in_array('json', $this->allowed)) { msAPI::response('ERROR', 'JSON handler not enabled in settings, please enable.'); } return msAPI::decode($data); break; case 'xml': if (!in_array('xml', $this->allowed)) { msAPI::response('ERROR', 'XML handler not enabled in settings, please enable.'); } if (!empty($data)) { if (function_exists('simplexml_load_string')) { return simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); } else { msAPI::response('ERROR', 'Simple XML functions not enabled on server. Must be enabled to read xml data.'); } } else { msAPI::response('ERROR', 'No post data received.'); } break; } }
/** * Generates plugin XML * This command generates the necessary files and configuration * to "plugin" to a preexisting Magento 2 object manager object. * * pestle.phar generate_plugin_xml Pulsestorm_Helloworld 'Magento\Framework\Logger\Monolog' 'Pulsestorm\Helloworld\Plugin\Magento\Framework\Logger\Monolog' * * @argument module_name Create in which module? [Pulsestorm_Helloworld] * @argument class Which class are you plugging into? [Magento\Framework\Logger\Monolog] * @argument class_plugin What's your plugin class name? [<$module_name$>\Plugin\<$class$>] * @command generate_plugin_xml */ function pestle_cli($argv) { // $module_info = askForModuleAndReturnInfo($argv); $module_info = getModuleInformation($argv['module_name']); $class = $argv['class']; $class_plugin = $argv['class_plugin']; $path_di = $module_info->folder . '/etc/di.xml'; if (!file_exists($path_di)) { $xml = simplexml_load_string(getBlankXml('di')); writeStringToFile($path_di, $xml->asXml()); output("Created new {$path_di}"); } $xml = simplexml_load_file($path_di); // $plugin_name = strToLower($module_info->name) . '_' . underscoreClass($class); // simpleXmlAddNodesXpath($xml, // "/type[@name=$class]/plugin[@name=$plugin_name,@type=$class_plugin]"); $type = $xml->addChild('type'); $type->addAttribute('name', $class); $plugin = $type->addChild('plugin'); $plugin->addAttribute('name', strToLower($module_info->name) . '_' . underscoreClass($class)); $plugin->addAttribute('type', $class_plugin); writeStringToFile($path_di, formatXmlString($xml->asXml())); output("Added nodes to {$path_di}"); $path_plugin = getPathFromClass($class_plugin); $body = implode("\n", [' //function beforeMETHOD($subject, $arg1, $arg2){}', ' //function aroundMETHOD($subject, $procede, $arg1, $arg2){return $proceed($arg1, $arg2);}', ' //function afterMETHOD($subject, $result){return $result;}']); $class_definition = str_replace('<$body$>', "\n{$body}\n", createClassTemplate($class_plugin)); writeStringToFile($path_plugin, $class_definition); output("Created file {$path_plugin}"); }
public function __construct($path) { $this->path = $path; if (file_exists($path)) { $this->xml = simplexml_load_string(file_get_contents($path)); } }
function testCorrect() { $xml = '<?xml version="1.0"?> <d:principal-search-property-set xmlns:d="DAV:"/>'; $serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/principals'); $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); $server->httpRequest = $request; $server->exec(); $this->assertEquals(200, $server->httpResponse->status, $server->httpResponse->body); $this->assertEquals(array('X-Sabre-Version' => [DAV\Version::VERSION], 'Content-Type' => ['application/xml; charset=utf-8']), $server->httpResponse->getHeaders()); $check = array('/d:principal-search-property-set', '/d:principal-search-property-set/d:principal-search-property' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1, '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1, '/d:principal-search-property-set/d:principal-search-property/d:description' => 2); $xml = simplexml_load_string($server->httpResponse->body); $xml->registerXPathNamespace('d', 'DAV:'); $xml->registerXPathNamespace('s', 'http://sabredav.org/ns'); foreach ($check as $v1 => $v2) { $xpath = is_int($v1) ? $v2 : $v1; $result = $xml->xpath($xpath); $count = 1; if (!is_int($v1)) { $count = $v2; } $this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body); } }
function gameStatus() { $homepage = file_get_contents('http://bsx.jlparry.com/status'); $xml = simplexml_load_string($homepage); print_r($xml); return $xml; }
/** * Converts a JSON string to a CFSimpleXML object. * * @param string|array $json (Required) Pass either a valid JSON-formatted string, or an associative array. * @param SimpleXMLElement $xml (Optional) An XML object to add nodes to. Must be an object that is an <code>instanceof</code> a <code>SimpleXMLElement</code> object. If an object is not passed, a new one will be generated using the classname defined for <code>$parser</code>. * @param string $parser (Optional) The name of the class to use to parse the XML. This class should extend <code>SimpleXMLElement</code>. Has a default value of <code>CFSimpleXML</code>. * @return CFSimpleXML An XML representation of the data. */ public static function to_xml($json, SimpleXMLElement $xml = null, $parser = 'CFSimpleXML') { // If there isn't an XML object, create one if (!$xml) { $xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><rootElement/>', $parser); } // If we haven't parsed the JSON, do it if (!is_array($json)) { $json = json_decode($json, true); if (function_exists('json_last_error')) { // Did we encounter an error? switch (json_last_error()) { case JSON_ERROR_DEPTH: throw new JSON_Exception('Maximum stack depth exceeded.'); case JSON_ERROR_CTRL_CHAR: throw new JSON_Exception('Unexpected control character found.'); case JSON_ERROR_SYNTAX: throw new JSON_Exception('Syntax error; Malformed JSON.'); case JSON_ERROR_STATE_MISMATCH: throw new JSON_Exception('Invalid or malformed JSON.'); } } else { throw new JSON_Exception('Unknown JSON error. Be sure to validate your JSON and read the notes on http://php.net/json_decode.'); } } // Hand off for the recursive work self::process_json($json, $xml, $parser); return $xml; }
/** * Initializes an empty package object * * @param null|string $definition optional package definition xml * @return Mage_Connect_Package */ protected function _init($definition = null) { if (!is_null($definition)) { $this->_packageXml = simplexml_load_string($definition); } else { $packageXmlStub = <<<END <?xml version="1.0"?> <package> <name /> <version /> <stability /> <license /> <channel /> <extends /> <summary /> <description /> <notes /> <authors /> <date /> <time /> <replace /> <compatible /> <dependencies /> </package> END; $this->_packageXml = simplexml_load_string($packageXmlStub); } return $this; }
public static function validateXMLResponse($headers, $response, $expected_http_code, $mandatoryElements, $mandatoryAttributes, $testObject) { $xml = null; // check if http code fits if ($headers["http_code"] != $expected_http_code) { $testObject->fail("Response has the wrong http code : " . $headers["http_code"] . "\n\n" . print_r($headers, true) . "\n\n" . $response); } // parse xml result try { $xml = simplexml_load_string($response); } catch (Exception $e) { echo "An error has been raised while processing the response: {$response}"; $testObject->fail("An exception has been raised: " . $e->getMessage() . "\n\n" . $e->getTraceAsString()); } if (!is_object($xml)) { $testObject->fail("There was an error while processing the response: {$response}"); } $existingAttributes = array(); $existingElements = array(); self::getAllElementsAndAttributes($xml, $existingElements, $existingAttributes); foreach ($mandatoryElements as $key => $value) { // test if all attributes are included $testObject->assertArrayHasKey($value, $existingElements, "Element missing in result: \n\n" . $response); } foreach ($mandatoryAttributes as $key => $value) { // test if all attributes are included $testObject->assertArrayHasKey($value, $existingAttributes, "Attribute missing in result: \n\n" . $response); } return $xml; }
private function xmlToArray($data) { $data = simplexml_load_string($data); $data = json_encode($data); $data = json_decode($data, true); return $data; }
public function viewFilesWithHandleAction() { $layoutHandle = $this->getRequest()->getParam('layout'); $title = "Files with layout updates for handle {$layoutHandle}"; if (!$layoutHandle) { } $updateFiles = Mage::helper('debug')->getLayoutUpdatesFiles(); /* @var $design Mage_Core_Model_Design_Package */ $design = Mage::getSingleton('core/design_package'); // search handle in the files $handleFiles = array(); foreach ($updateFiles as $file) { $filename = $design->getLayoutFilename($file, array('_area' => $design->getArea(), '_package' => $design->getPackageName(), '_theme' => $design->getTheme('layout'))); if (!is_readable($filename)) { continue; } $fileStr = file_get_contents($filename); $fileXml = simplexml_load_string($fileStr, Mage::getConfig()->getModelClassName('core/layout_element')); if (!$fileXml instanceof SimpleXMLElement) { continue; } $result = $fileXml->xpath("/layout/" . $layoutHandle); if ($result) { $handleFiles[$filename] = $result; } } // TODO: search handle in db layout updates $block = new Mage_Core_Block_Template(); $block->setTemplate('debug/handledetails.phtml'); $block->assign('title', $title); $block->assign('handleFiles', $handleFiles); echo $block->toHtml(); }