/** * @param SimpleXmlElement $node * @return string */ function getNodeTitle($node) { if ($node->children()) { $nodeName = $node->children()[0]->getName(); $subNodeName = getNodeTitle($node->children()[0]); return $nodeName . ($subNodeName ? ' > ' . $subNodeName : ''); } return ''; }
/** * Parse the input SimpleXmlElement into an array * * @param SimpleXmlElement $node xml to parse * @return array */ protected function parseXml($node) { $data = array(); foreach ($node->children() as $key => $subnode) { if ($subnode->count()) { $value = $this->parseXml($subnode); if ($subnode->attributes()) { foreach ($subnode->attributes() as $attrkey => $attr) { $value['@' . $attrkey] = (string) $attr; } } } else { $value = (string) $subnode; } if ($key === 'item') { if (isset($subnode['key'])) { $data[(string) $subnode['key']] = $value; } elseif (isset($data['item'])) { $tmp = $data['item']; unset($data['item']); $data[] = $tmp; $data[] = $value; } } elseif (key_exists($key, $data)) { if (false === is_array($data[$key])) { $data[$key] = array($data[$key]); } $data[$key][] = $value; } else { $data[$key] = $value; } } return $data; }
/** * Returns the form title from the h:title element * * @return string */ public function getTitle() { if (empty($this->title)) { $this->title = $this->_xml->children('h', true)->head->children('h', true)->title; } return $this->title; }
function set_search_results($search_entry) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://api.bing.net/xml.aspx?AppId=753288BB83E89E80D75157ACE521DB923766F77B&Verstion=2.2&Market=en-US&Query=' . $search_entry->input_user_query . '&Sources=web+spell&web.count=' . TOTAL_SEARCH_NO . '&xmltype=elementbased'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $ret = curl_exec($ch); curl_close($ch); $xml_object = new SimpleXmlElement($ret); $children = $xml_object->children('http://schemas.microsoft.com/LiveSearch/2008/04/XML/web'); $counter = 0; foreach ($children->Web->Results->WebResult as $node) { $this->array_of_results[$counter]->title = $node->Title; $this->array_of_results[$counter]->description = $node->Description; $this->array_of_results[$counter]->url = $node->Url; $this->array_of_results[$counter]->display_url = $node->DisplayUrl; $counter++; } }
/** * @param string $query * * @return array */ protected function executeQuery($query) { $content = $this->getAdapter()->getContent($query); try { $xml = new \SimpleXmlElement($content); } catch (\Exception $e) { throw new NoResultException(sprintf('Could not execute query %s', $query)); } $dataNode = $xml->children('gml', true)->featureMember->children('', true)->Hostip; if (isset($dataNode->ipLocation)) { $lngLat = explode(',', (string) $dataNode->ipLocation->children('gml', true)->pointProperty->Point->coordinates); } else { $lngLat = array(null, null); } $city = (string) $dataNode->children('gml', true)->name; $country = (string) $dataNode->countryName; $countryCode = (string) $dataNode->countryAbbrev; return array_merge($this->getDefaults(), array('latitude' => $lngLat[1], 'longitude' => $lngLat[0], 'city' => $city, 'country' => $country, 'countryCode' => $countryCode)); }
/** * Parse the input SimpleXmlElement into an array * * @param SimpleXmlElement $node xml to parse * @return array */ protected function parseXml($node) { $data = array(); foreach ($node->children() as $key => $subnode) { if ($subnode->count()) { $value = $this->parseXml($subnode); } else { $value = (string) $subnode; } if ($key === 'item') { if (isset($subnode['key'])) { $data[(string) $subnode['key']] = $value; } elseif (isset($data['item'])) { $tmp = $data['item']; unset($data['item']); $data[] = $tmp; $data[] = $value; } } else { $data[$key] = $value; } } return $data; }
/** * Parse the input SimpleXmlElement into an array. * * @param SimpleXmlElement $node xml to parse * * @return array */ private function parseXml($node) { $data = array(); if ($node->attributes()) { foreach ($node->attributes() as $attrkey => $attr) { $data['@' . $attrkey] = (string) $attr; } } foreach ($node->children() as $key => $subnode) { if ($subnode->count()) { $value = $this->parseXml($subnode); } elseif ($subnode->attributes()) { $value = array(); foreach ($subnode->attributes() as $attrkey => $attr) { $value['@' . $attrkey] = (string) $attr; } $value['#'] = (string) $subnode; } else { $value = (string) $subnode; } if ($key === 'item') { if (isset($value['@key'])) { if (isset($value['#'])) { $data[(string) $value['@key']] = $value['#']; } else { $data[(string) $value['@key']] = $value; } } else { $data['item'][] = $value; } } elseif (array_key_exists($key, $data) || $key == "entry") { if (false === is_array($data[$key]) || false === isset($data[$key][0])) { $data[$key] = array($data[$key]); } $data[$key][] = $value; } else { $data[$key] = $value; } } return $data; }
/** * Checks if a <...> node has <data> children * * @param SimpleXmlElement $field * @return boolean TRUE if at least one child is <data>, FALSE otherwise */ protected function _has_data_children($field) { $dataChilds = count($field->children()) > 0; if ($dataChilds) { $dataChilds = false; foreach ($field->children() as $child) { /** @var $child SimpleXmlElement */ if ($child->getName() == 'data') { $dataChilds = true; break; } } } return $dataChilds; }
public function LoadAdvisor($_IDIntern, $_BaliseName) { $extension = null; //extension if ($_BaliseName == "cieReview") { $extension = '_CieEVL.xml'; } if ($_BaliseName == "review1") { $extension = '_AdvRev1EVL.xml'; } if ($_BaliseName == "review2") { $extension = '_AdvRev2EVL.xml'; } //Déclaration du tableau dans lequelle sera stoqué tous les rapports $obj = array(); //Si le fichier souhaiter existe le charge en mémoire et récupère toute les informations if (file_exists(parent::DefaultXMLPath . 'evaluation/' . $_IDIntern . $extension)) { $_Simple = new SimpleXmlElement(parent::DefaultXMLPath . 'evaluation/' . $_IDIntern . $extension, 0, true); //Pour tout les éléments contenu dans le fichier XML, sous la balise passé en paramètre, l'ajouter dans le tableau $obj foreach ($_Simple->children() as $Enfant) { if ($Enfant->getName() == $_BaliseName) { foreach ($Enfant->children() as $Info) { $obj[$Info->getName()] = (string) $Info; } } } } $Result = new obj($obj); //Transforme les journeaux en objet utilisable et les retourne return $Result; }
/** Convert an XML-RPC value element to a PHP value Parameters: param - (SimpleXmlElement) XML element containing the XML-RPC 'value' node Returns: (mixed) The PHP value */ protected function _decodeParam(SimpleXmlElement $param) { $children = $param->children(); $child = $children[0]; switch ($child->getName()) { case 'struct': $values = array(); foreach ($child->member as $member) { $values[(string) $member->name] = $this->_decodeParam($member->value); } return $values; case 'array': $values = array(); foreach ($child->data->value as $value) { $values[] = $this->_decodeParam($value); } return $values; case 'nil': return null; case 'i4': case 'int': return (int) $child; case 'double': return (double) $child; case 'boolean': // $child is an object SimpleXmlElement which will 'toString' to '0' / '1', which boolean casts properly return (bool) (string) $child; case 'base64': case 'dateTime.iso8601': case 'string': return (string) $child; default: throw new OpenReact_XmlRpc_Client_UnsupportedXmlRpcValueTypeException('Unsupported XML-RPC value type `%s` found.', array($child->getName())); } }
/** * Parse an edifact segment group and return the correponding * EDI_EDIFACT_SegmentGroup object. * * @param string $id Id of the segment group (SG1, SG2...) * @param array &$data Array of CDE or data elements * @param SimpleXmlElement $mapping Corresponding mapping node * @param bool $req set this to false if the CDE is optional * * @access protected * @return EDI_EDIFACT_SegmentGroup * @throws EDI_Exception */ protected function parseSegmentGroup($id, &$data, $mapping, $req = true) { if ($req && empty($data)) { throw new EDI_Exception("segment group \"{$id}\" is required.", EDI_Exception::E_EDI_SYNTAX_ERROR); } $elt = new EDI_EDIFACT_SegmentGroup(); $children = $mapping->children(); $hasChildren = false; foreach ($children as $node) { $nodeName = (string) $node->getName(); $nodeId = (string) $node['id']; $nodeReq = (string) $node['required'] == 'true'; $nodeMaxRepeat = (int) $node['maxrepeat']; if ($nodeName == 'segment') { if (empty($data)) { if ($req && $nodeReq) { throw new EDI_Exception(sprintf('segment "%s" is required in group "%s"', $nodeId, $id), EDI_Exception::E_EDI_SYNTAX_ERROR); } break; } list($sId, $sData) = $data[0]; if ($sId != $nodeId) { if ($req && $nodeReq) { throw new EDI_Exception(sprintf('segment "%s" is required in group "%s"', $nodeId, $id), EDI_Exception::E_EDI_SYNTAX_ERROR); } else { if ($nodeReq) { // we can skip this group... break; } } continue; } if ($nodeMaxRepeat > 1) { $e = $this->parseSegmentRepetition($sId, $data, $nodeMaxRepeat, $nodeReq); } else { $e = $this->parseSegment($sId, $data, $nodeReq); } } else { if ($nodeName == 'group') { if ($nodeMaxRepeat > 1) { $e = $this->parseSegmentGroupRepetition($nodeId, $data, $node, $nodeMaxRepeat, $nodeReq); } else { $e = $this->parseSegmentGroup($nodeId, $data, $node, $nodeReq); } } } if ($e !== null) { $elt[] = $e; $hasChildren = true; } } $elt->id = $id . '_group'; return $hasChildren ? $elt : null; }
/** * Get a list of all builds of a project * * @param string $projectName * @param integer $start * @param integer $limit * * @return stdClass */ private function _getLogMessagesArr($projectName, $buildTime, $start, $limit = null) { $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir(); $historyFile = $statusDir . DIRECTORY_SEPARATOR . $projectName . '.history'; $project = new Xinc_Project(); $project->setName($projectName); $totalCount = 0; try { $build = Xinc_Build::unserialize($project, $buildTime, $statusDir); $timezone = $build->getConfigDirective('timezone'); if ($timezone !== null) { Xinc_Timezone::set($timezone); } $detailDir = Xinc_Build_History::getBuildDir($project, $buildTime); $logXmlFile = $detailDir . DIRECTORY_SEPARATOR . 'buildlog.xml'; if (file_exists($logXmlFile)) { /** * Add fopen() to the function to just get the loglines * that we need. * the bigger the logfiles get, the more this gets a * performance problem */ $xmlStr = ''; $pos = 0; $fh = fopen($logXmlFile, 'r'); $xmlStr = fgets($fh); $xmlStr .= fgets($fh); $tagOpen = false; while ($pos < $start && ($message = $this->_getNextMessage($fh)) !== false) { $pos++; $totalCount++; } if ($limit != null) { $addClosingTag = true; while ($pos < $start + $limit && ($message = $this->_getNextMessage($fh)) !== false) { $xmlStr .= $message; $pos++; $totalCount++; } $xmlStr .= '</build>'; } else { while (($message = $this->_getNextMessage($fh)) !== false) { $xmlStr .= $message; $totalCount++; $pos++; } $xmlStr .= '</build>'; } $tagOpen = false; $tagClosed = false; while (($message = $this->_getNextMessage($fh)) !== false) { $totalCount++; $pos++; } fclose($fh); $logXml = new SimpleXMLElement($xmlStr); } else { $logXml = new SimpleXmlElement('<log/>'); } $totalCount = $pos; //count($logXml->children()); $i = $pos; $logmessages = array(); $id = $totalCount - $start; foreach ($logXml->children() as $logEntry) { $attributes = $logEntry->attributes(); $logmessages[] = array('id' => $id--, 'date' => (string) $attributes->timestamp, 'stringdate' => date('Y-m-d H:i:s', (int) $attributes->timestamp), 'timezone' => Xinc_Timezone::get(), 'priority' => (string) $attributes->priority, 'message' => base64_decode($logEntry)); } /** * restore to system timezone */ $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone'); if ($xincTimezone !== null) { Xinc_Timezone::set($xincTimezone); } else { Xinc_Timezone::reset(); } //$logmessages = array_slice($logmessages, $start, $limit, false); } catch (Exception $e1) { $totalCount = 0; $logmessages = array(); } $object = new stdClass(); $object->totalmessages = $totalCount; $object->logmessages = $logmessages; //return new Xinc_Build_Iterator($builds); return $object; }
private function _loadXML() { $feed = file_get_contents($this->_query_link); $xml = new SimpleXmlElement($feed); //Use that namespace $namespaces = $xml->getNameSpaces(true); //Now we don't have the URL hard-coded $dc = (array) $xml->children($namespaces['dc']); //load data to $this->this results foreach ($dc as $key => $value) { switch ($key) { case 'creator': $this->_fetchAuthors($value); break; case 'identifier': $this->_fetchIds($value); break; case 'title': $this->_fetchTitle($value); break; case 'publisher': $this->_fetchPublisher($value); break; case 'language': $this->_fetchLanguage($value); break; case 'description': $this->_fetchDescription($value); break; case 'subject': $this->_fetchSubject($value); break; case 'format': $this->_fetchFormat($value); break; } } }
function set_search_results($search_entry) { /*echo "test1";*/ /*var_dump ($search_entry->array_of_query_types["input_user_query"]);*/ $request = 'http://api.bing.net/xml.aspx?AppId=753288BB83E89E80D75157ACE521DB923766F77B&Verstion=2.2&Market=en-US&Query=' . $search_entry->input_user_query . '&Sources=web+spell&web.count=' . TOTAL_SEARCH_NO . '&xmltype=elementbased'; /*echo "test2";*/ //NB use urlencode($query) function put in later //echo($request); $this->search_result = file_get_contents($request); $xml_object = new SimpleXmlElement($this->search_result); $children = $xml_object->children('http://schemas.microsoft.com/LiveSearch/2008/04/XML/web'); /*print_r($children);*/ $counter = 0; foreach ($children->Web->Results->WebResult as $node) { $this->array_of_results[$counter]->title = $node->Title; $this->array_of_results[$counter]->description = $node->Description; $this->array_of_results[$counter]->url = $node->Url; $this->array_of_results[$counter]->display_url = $node->DisplayUrl; $counter++; } /*$namespaces = $node->getNamespaces(true);*/ /*var_dump($namespaces);*/ }
/* Run request on twitter API as user. */ $content = $to->OAuthRequest('https://twitter.com/account/verify_credentials.xml', array(), 'GET'); //$content = $to->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => 'twitter'), 'POST'); //$content = $to->OAuthRequest('https://twitter.com/statuses/replies.xml', array(), 'POST'); break; } ?> <?php if (!isset($_GET["oauth_token"])) { echo $content; } else { //response from twitter $aa = array(); $xml = new SimpleXmlElement($content); foreach ($xml->children() as $val) { $aa[] = $val; } //print_r($aa); exit; $username = "******" . $aa[0]; $firstname = $aa[1]; $img_url = $aa[5]; //add the twitter information if ($_SESSION["userrole"] == 1) { updateTWuser($_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret'], $tok["user_id"], $firstname); url_redirect(DOCROOT . "admin/social-media-account/"); } //login function easyRegister($username, $firstname, "", "", $img_url, 2); /* $content1=$to->OAuthRequest('http://twitter.com/statuses/friends.xml?user_id='.$aa[0], array(), 'GET');