Example #1
1
function parse_server_status_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $node = $dom->getElementsByTagname('server')->item(0);
    if (is_null($node)) {
        return false;
    }
    if (!$node->hasAttribute('name')) {
        return false;
    }
    if (!$node->hasAttribute('status')) {
        return false;
    }
    return array('name' => $node->getAttribute('name'), 'status' => $node->getAttribute('status'));
}
Example #2
0
 private function getDomObject()
 {
     if ($this->_verbose > 2) {
         $this->log('IN:[' . __FUNCTION__ . ']', 0, "purple");
     }
     if ($this->_verbose > 1) {
         $this->log("Content length: " . strlen($this->_content), 0, "light_purple");
     }
     $DOM = new \DomDocument();
     switch ($this->_domType) {
         case "xml":
             if ($this->_verbose > 2) {
                 $this->log('<' . __LINE__ . '> DOMDocument->loadXML', 0, "purple");
             }
             @$DOM->loadXML($this->_content);
             break;
         case "html":
             if ($this->_verbose > 2) {
                 $this->log('<' . __LINE__ . '> DOMDocument->loadXML');
             }
             @$DOM->loadHtml($this->_content);
             break;
         default:
             throw new \Exception("Unknwon DOM type used to load content \"" . $this->_domType . "\"");
             break;
     }
     return $DOM;
 }
Example #3
0
 /**
  * Logs into Windows Live
  *
  * @return true on success else error
  */
 public function login()
 {
     // Register device
     $register = $this->registerDevice();
     // Get binary DA token
     $response = $this->getBinaryDAToken($this->messageid, $this->deviceUserName, $this->devicePassword);
     $responsedom = new DomDocument();
     $responsedom->loadXML($response);
     $cipherValues = $responsedom->getElementsbyTagName("CipherValue");
     $this->cipherValue = $cipherValues->item(0)->textContent;
     if (!empty($this->cipherValue)) {
         // Get security tokens
         $response = $this->getSecurityTokens($this->cipherValue);
         $responsedom = new DomDocument();
         $responsedom->loadXML($response);
         $cipherValues = $responsedom->getElementsbyTagName("CipherValue");
         $this->securityToken0 = $cipherValues->item(0)->textContent;
         $this->securityToken1 = $cipherValues->item(1)->textContent;
         $this->keyIdentifier = $responsedom->getElementsbyTagName("KeyIdentifier")->item(0)->textContent;
         if (empty($this->keyIdentifier) || empty($this->securityToken0) || empty($this->securityToken1)) {
             $this->_error = "Failed to get security tokens.";
         } else {
             return true;
         }
     } else {
         $this->_error = "Failed to get binary DA token.";
     }
 }
Example #4
0
 /**
  * Get the answer value as an xml element
  * @param \DomDocument $dom
  * @param \Jazzee\Entity\Answer $answer
  * @param integer $version
  * @return \DomElement
  */
 public function getXmlAnswer(\DomDocument $dom, \Jazzee\Entity\Answer $answer, $version)
 {
     $eXml = $dom->createElement('element');
     $eXml->setAttribute('elementId', $this->_element->getId());
     $eXml->setAttribute('title', htmlentities($this->_element->getTitle(), ENT_COMPAT, 'utf-8'));
     $eXml->setAttribute('name', htmlentities($this->_element->getName(), ENT_COMPAT, 'utf-8'));
     $eXml->setAttribute('type', htmlentities($this->_element->getType()->getClass(), ENT_COMPAT, 'utf-8'));
     $eXml->setAttribute('weight', $this->_element->getWeight());
     $elementsAnswers = $answer->getElementAnswersForElement($this->_element);
     switch ($version) {
         case 1:
             if ($value = $this->rawValue($answer)) {
                 $eXml->appendChild($dom->createCDATASection(preg_replace('/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $value)));
             }
             break;
         case 2:
             $value = null;
             if (isset($elementsAnswers[0])) {
                 $value = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getValue();
                 $name = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getName();
                 $id = $this->_element->getItemById($elementsAnswers[0]->getEInteger())->getId();
             }
             if ($value) {
                 $vXml = $dom->createElement('value');
                 $vXml->setAttribute('valueId', $id);
                 $vXml->setAttribute('name', htmlentities($name, ENT_COMPAT, 'utf-8'));
                 $vXml->appendChild($dom->createCDATASection(preg_replace('/[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $value)));
                 $eXml->appendChild($vXml);
             }
             break;
     }
     return $eXml;
 }
Example #5
0
function returnXPathObject($item)
{
    $xmlPageDom = new DomDocument();
    @$xmlPageDom->loadHTML($item);
    $xmlPageXPath = new DOMXPath($xmlPageDom);
    return $xmlPageXPath;
}
Example #6
0
 /**
  * Applies action
  *
  * @return  boolean success
  */
 protected function main()
 {
     $flow = Nexista_Flow::Singleton('Nexista_Flow');
     $file_path = Nexista_Path::parseInlineFlow($this->params['xsl']);
     $xslfile = NX_PATH_APPS . $file_path;
     if (!is_file($xslfile)) {
         Nexista_Error::init('XSL Action - file unavailable: ' . $xslfile, NX_ERROR_FATAL);
     }
     $xsl = new DomDocument('1.0', 'UTF-8');
     $xsl->substituteEntities = false;
     $xsl->resolveExternals = false;
     $xslfilecontents .= file_get_contents($xslfile);
     $xsl->loadXML($xslfilecontents);
     $xsl->documentURI = $xslfile;
     $use_xslt_cache = "yes";
     if ($use_xslt_cache != "yes" || !class_exists('xsltCache')) {
         $xslHandler = new XsltProcessor();
     } else {
         $xslHandler = new xsltCache();
     }
     $xslHandler->importStyleSheet($xsl);
     $my_output = $xslHandler->transformToXML($flow->flowDocument);
     if ($my_output === false) {
         Nexista_Error::init('XSL Action - Error processing XSL file: ' . $xslfile, NX_ERROR_FATAL);
         return false;
     }
     $new_node = $this->params['new_node'];
     Nexista_Flow::add($new_node, $my_output);
     return true;
 }
function hal_parse($url)
{
    $url = trim(html_entity_decode($url), "\"' ");
    $infos = parse_url($url);
    $ip = gethostbyname($infos['host']);
    if ($ip != '193.48.96.10') {
        spip_log("Url invalid", _LOG_ERREUR);
        return;
    }
    spip_log(sprintf("[hal_parse] init_http(%s)", $url), _LOG_DEBUG);
    $content = recuperer_page($url);
    spip_log(sprintf("[hal_parse] init_http(%s): Done", $url), _LOG_DEBUG);
    $dom = new DomDocument('1.0', 'UTF-8');
    $dom->preserveWhiteSpace = false;
    $str = mb_convert_encoding($content, "HTML-ENTITIES");
    @$dom->loadHTML($str);
    $xpath = new DOMXpath($dom);
    $entries = $xpath->query('//div[@id="res_script"]');
    if ($entries->length == 0) {
        spip_log("No tag found ...", _LOG_ERREUR);
        return;
    }
    $res_script = $dom->saveXML($entries->item(0));
    return $res_script;
}
 /**
  * 
  * @param string $html
  */
 public function exec($html)
 {
     mb_language('Japanese');
     // 1.プリプロセス
     // scriptテキスト削除
     // script内に文字列リテラルの閉じタグがあるとDomDocumentがscriptのソースを#text扱いしてしまうので
     // script内の文字を削除する
     // 正規表現で削除しようとするとSegmentation faultが発生する(StackOverFlow?)ので
     // simple_html_domでscript内文字列を削除
     // MAX_FILE_SIZEの制限にひっかかったので、ソースを編集してデフォルトの3倍に変更している
     $simpleHtml = str_get_html($html);
     foreach ($simpleHtml->find('script') as $script) {
         $script->innertext = '';
     }
     $html = $simpleHtml->outertext;
     // トリム
     //		$html = preg_replace('/(\s| )+/mi', ' ', $html);
     // 2. dom生成
     $doc = new DomDocument("1.0", "utf-8");
     @$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
     $node = $doc->getElementsByTagName('body')->item(0);
     $this->preProcessedInput = $node->textContent;
     // 3.プロパティを初期化
     $this->domXPath = new DomXPath($doc);
     $this->title = @$doc->getElementsByTagName('title')->item(0)->textContent;
     $text = $this->scan($node);
     $this->textAll = $text;
     $this->domCountAll = $this->domCount;
     $this->pancutuationCountAll = $this->calcKutenScore($text) + $this->calcTotenScore($text);
     $this->textLengthAll = mb_strlen($text);
     $this->highScore = -1000000;
     $this->extracedNode = null;
     // 4.実行
     $this->extract($node);
 }
 /**
  * Serialize an associative array of pci properties into a pci xml
  *
  * @param array $properties
  * @param string $ns
  * @return string
  */
 private function serializePortableProperties($properties, $ns = '', $nsUri = '', $name = null, $element = null)
 {
     $document = null;
     $result = '';
     if ($element === null) {
         $document = new \DomDocument();
         $element = $ns ? $document->createElementNS($nsUri, $ns . ':properties') : $document->createElement('properties');
         $document->appendChild($element);
     } else {
         $newElement = $ns ? $element->ownerDocument->createElementNS($nsUri, $ns . ':properties') : $element->ownerDocument->createElement('properties');
         $element->appendChild($newElement);
         $element = $newElement;
     }
     if ($name !== null) {
         $element->setAttribute('key', $name);
     }
     foreach ($properties as $name => $value) {
         if (is_array($value)) {
             $this->serializePortableProperties($value, $ns, $nsUri, $name, $element);
         } else {
             $entryElement = $ns ? $element->ownerDocument->createElementNS($nsUri, $ns . ':entry') : $element->ownerDocument->createElementNS('entry');
             $entryElement->setAttribute('key', $name);
             $entryElement->appendChild(new \DOMText($value));
             $element->appendChild($entryElement);
         }
     }
     if ($document !== null) {
         foreach ($document->childNodes as $node) {
             $result .= $document->saveXML($node);
         }
     }
     return $result;
 }
Example #10
0
 static function response($status, $status_message, $domdocument = null)
 {
     $dom = new DomDocument('1.0', 'UTF-8');
     $results = $dom->appendChild($dom->createElement('response'));
     $results->appendChild($dom->createElement('status', $status));
     $results->appendChild($dom->createElement('status_message', $status_message));
     if (is_null($domdocument)) {
         $domdocument = new DomDocument('1.0', 'UTF-8');
         $domdocument->appendChild($domdocument->createElement('data'));
     }
     if ($domdocument->documentElement->nodeName === 'data') {
         $newdom = $domdocument;
     } else {
         $newdom = new DOMDocument('1.0', 'UTF-8');
         $data = $newdom->appendChild($newdom->createElement('data'));
         foreach ($domdocument->documentElement->childNodes as $domElement) {
             $domNode = $newdom->importNode($domElement, true);
             $data->appendChild($domNode);
         }
     }
     $import = $dom->importNode($newdom->documentElement, TRUE);
     $results->appendChild($import);
     $dom->formatOutput = true;
     echo $dom->saveXML();
 }
 function createCollection($theUser, $pid, $soapClient)
 {
     $dom = new DomDocument("1.0", "UTF-8");
     $dom->formatOutput = true;
     $rootElement = $dom->createElement("foxml:digitalObject");
     $rootElement->setAttribute('PID', "{$pid}");
     $rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#");
     $rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
     $rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-0.xsd");
     $dom->appendChild($rootElement);
     //create standard fedora stuff
     $this->createStandardFedoraStuff($theUser, $dom, $rootElement);
     //create dublin core
     $this->createDCStream($theUser, $dom, $rootElement);
     $value = $this->createPolicyStream($theUser, $dom, $rootElement);
     if (!$value) {
         return false;
         //error should already be logged.
     }
     $this->createCollectionPolicyStream($theUser, $dom, $rootElement);
     try {
         $params = array('objectXML' => $dom->saveXML(), 'format' => "foxml1.0", 'logMessage' => "Fedora Object Ingested");
         $object = $soapClient->__soapCall('ingest', array($params));
     } catch (exception $e) {
         drupal_set_message(t('Error Ingesting Personal Collection Object! ') . $e->getMessage(), 'error');
         return false;
     }
     return true;
 }
Example #12
0
 public function getForm($formId, $params, $headers)
 {
     /** @var DOMElement $form */
     $dom = new DomDocument();
     libxml_use_internal_errors(true);
     $dom->loadHTML($this->response());
     $xpath = new DOMXpath($dom);
     $form = $xpath->query("//form[@id='{$formId}']")->item(0);
     $elements = $xpath->query('//input');
     $form_params = [];
     $allowedTypes = ["hidden", "text", "password"];
     foreach ($elements as $element) {
         /** @var DOMElement $element */
         $type = $element->getAttribute("type");
         if (in_array($type, $allowedTypes)) {
             $name = $element->getAttribute("name");
             $value = $element->getAttribute("value");
             $form_params[$name] = $value;
         }
     }
     $headers = array_merge(["Referer" => $this->baseUri], $headers);
     $url = Uri::resolve(new Uri($this->baseUri), $form->getAttribute("action"))->__toString();
     $method = strtoupper($form->getAttribute("method"));
     return ["method" => $method, "url" => $url, "headers" => $headers, "params" => array_merge($form_params, $params)];
 }
Example #13
0
 function xslt_process($xsltproc, $xml_arg, $xsl_arg, $xslcontainer = null, $args = null, $params = null)
 {
     // Start with preparing the arguments
     $xml_arg = str_replace('arg:', '', $xml_arg);
     $xsl_arg = str_replace('arg:', '', $xsl_arg);
     // Create instances of the DomDocument class
     $xml = new DomDocument();
     $xsl = new DomDocument();
     $phpversion = explode('.', PHP_VERSION);
     $phpversionid = $phpversion[0] * 10000 + $phpversion[1] * 100 + $phpversion[2];
     // Load the xml document and the xsl template
     if ($phpversionid >= 50302 && LIBXML_VERSION >= 20700) {
         $xmlOptions = LIBXML_PARSEHUGE;
     } else {
         $xmlOptions = 0;
     }
     $xml->loadXML($args[$xml_arg], $xmlOptions);
     $xsl->loadXML(file_get_contents($xsl_arg), $xmlOptions);
     // Load the xsl template
     $xsltproc->importStyleSheet($xsl);
     // Set parameters when defined
     if ($params) {
         foreach ($params as $param => $value) {
             $xsltproc->setParameter("", $param, $value);
         }
     }
     // Start the transformation
     $processed = $xsltproc->transformToXML($xml);
     // Put the result in a file when specified
     if ($xslcontainer) {
         return @file_put_contents($xslcontainer, $processed);
     } else {
         return $processed;
     }
 }
Example #14
0
 /**
  * Renders an rss feed containing the newest plugins.
  *
  * @param int $limit How many plugins to display (optional, default 20)
  */
 public function newest_action($limit = 20)
 {
     $doc = new DomDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     $doc->encoding = 'utf-8';
     $rss = $doc->appendChild($this->create_xml_element($doc, 'rss', null, array('version' => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom')));
     $channel = $rss->appendChild($doc->createElement('channel'));
     $channel->appendChild($this->create_xml_element($doc, 'title', 'Stud.IP Plugin Marktplatz - Neueste Plugins'));
     $channel->appendChild($this->create_xml_element($doc, 'description', 'Liste der neuesten Plugins auf dem Stud.IP Plugin Marktplatz'));
     $channel->appendChild($this->create_xml_element($doc, 'link', 'http://plugins.studip.de'));
     $channel->appendChild($this->create_xml_element($doc, 'lastBuildDate', gmdate('D, d M Y H:i:s T')));
     $channel->appendChild($this->create_xml_element($doc, 'generator', _('Stud.IP Plugin Marktplatz')));
     $channel->appendChild($this->create_xml_element($doc, 'atom:link', null, array('rel' => 'self', 'type' => 'application/rss+xml', 'href' => $this->absolute_url_for('rss/newest'))));
     $plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY mkdate DESC");
     foreach ($plugins as $plugin) {
         if (count($plugin->releases) === 0) {
             continue;
         }
         $rss_plugin = $channel->appendChild($doc->createElement('item'));
         $rss_plugin->appendChild($this->create_xml_element($doc, 'title', $plugin->name));
         $rss_plugin->appendChild($this->create_xml_element($doc, 'link', $this->absolute_url_for('presenting/details/' . $plugin->id)));
         $rss_plugin->appendChild($this->create_xml_element($doc, 'guid', $this->absolute_url_for('presenting/details/' . $plugin->id), array('isPermaLink' => 'true')));
         $rss_plugin->appendChild($this->create_xml_element($doc, 'description', $plugin->description, array(), false));
         if ($plugin->user) {
             $rss_plugin->appendChild($this->create_xml_element($doc, 'author', $plugin->user->email . ' (' . $plugin->user->getFullname() . ')'));
         }
     }
     $this->render_text($doc->saveXML());
 }
Example #15
0
 public function fillInXml($xml, $formName, $formId, $values)
 {
     $dom = new DomDocument('1.0', sfConfig::get('sf_charset', 'UTF-8'));
     @$dom->loadXML($xml);
     $dom = $this->fillInDom($dom, $formName, $formId, $values);
     return $dom->saveXML();
 }
Example #16
0
 public function run($str = NULL)
 {
     if ($str == NULL) {
         return $this;
     }
     $document = jqm_use($this->node->_parentElement);
     $dom = $document->_DOM;
     if ($dom->doctype) {
         $dom->removeChild($dom->doctype);
     }
     $find = $this->node->getPathById($dom);
     if (!$find) {
         $find = $this->node->_path;
     }
     $xpath = new DomXpath($dom);
     $find = $xpath->query($find);
     if ($find->length > 0) {
         $child = new DomDocument();
         $child->loadHtml($str);
         if ($child->doctype) {
             $child->removeChild($child->doctype);
         }
         $child->normalize();
         $frag = $dom->importNode($child->firstChild->firstChild->firstChild, true);
         $save = $find->item(0)->parentNode->insertBefore($frag, $find->item(0));
         $this->node->_path = $save->nextSibling->getNodePath();
         $document->_DOM = $dom;
     }
     return $this;
 }
Example #17
0
 function execute($requestXml)
 {
     $this->init();
     if (is_string($requestXml)) {
         $dom = new DomDocument();
         $dom->preserveWhiteSpace = FALSE;
         if ($dom->loadXML($xml)) {
             $requestXml = $dom->firstChild;
         }
     }
     //is_string()
     $this->warnings = array();
     if (is_object($requestXml) && get_class($requestXml) == "DOMElement") {
         $action = $requestXml->getAttribute('action');
         $this->requestNo = $requestXml->getAttribute('no');
         $this->reset();
         $this->requestXml = $requestXml->ownerDocument->saveXML($requestXml);
         foreach ($requestXml->attributes as $attr) {
             $this->params[$attr->name] = $attr->value;
         }
         //debug($this->params);
         if (method_exists($this, $action)) {
             $this->content = $this->{$action}();
             return $this->responseData();
         } else {
             return $this->invalidRequest($requestXml, 405);
         }
     } else {
         return $this->invalidRequest($requestXml);
     }
 }
	function getXMLSing($xmlHon,$priv_key){
		//Carga Certificado
		$xml = new DomDocument();
		$xml->loadXML($xmlHon);
		//Carga prosedimiento de proceso de cadena original
		$xsl = new DomDocument;
		$xsl->load("ostring.xsl");
		$proc = new xsltprocessor();
		$proc->importStyleSheet($xsl);
		$original =$proc->transformToXML($xml);
		//firma la cadena original
		
		//$fp = $cert[0]['certificates']['key'];
		//$priv_key = $f['key'];
		//die($f['key']);
		//fclose($fp);
		$pkeyid = openssl_get_privatekey($priv_key);
		openssl_sign($original, $signature, $pkeyid,OPENSSL_ALGO_MD5);
		openssl_free_key($pkeyid);
		//coloca el sello en xml
		$esqueletonew=$xmlHon;
		$esqueletonew=str_replace("#1#",base64_encode($signature),$esqueletonew);
		$xmlReturn[1]=$esqueletonew;
		$xmlReturn[2]=$original;
		$xmlReturn[3]=base64_encode($signature);
		return $xmlReturn;
	}
Example #19
0
 public function process($args)
 {
     $answer = "";
     $args = trim($args);
     if (strlen($args) > 0) {
         $entrada = urlencode($args);
         $url = "https://www.google.com.mx/search?q={$entrada}&oq=200&aqs=chrome.1.69i57j69i59j69i65l2j0l2.3015j0j8&client=ubuntu-browser&sourceid=chrome&es_sm=122&ie=UTF-8";
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36');
         $html = curl_exec($ch);
         $web = new DomDocument();
         @$web->loadHTML($html);
         $nodos = @$web->getElementById('topstuff')->getElementsByTagName('div');
         $answer = "No pude convertir lo que me pides.";
         if ($nodos) {
             $nodos = iterator_to_array($nodos);
             if (count($nodos) === 6) {
                 $answer = utf8_decode($nodos[3]->nodeValue . " " . $nodos[4]->nodeValue);
             }
         }
     } else {
         $answer = "Ingresa una expresion.";
     }
     $this->reply($answer, $this->currentchannel, $this->nick);
 }
function getImportantActs($xml_url, $xsl_filename, $n_nodes)
{
    try {
        // read the xml from url
        $xmldoc = new DomDocument();
        $xmldoc->load($xml_url);
        // read xslt file
        $xsldoc = new DomDocument();
        $xsldoc->load($xsl_filename);
        $xsl = new XSLTProcessor();
        $xsl->importStyleSheet($xsldoc);
        // trasforma XML secondo l'XSLT ed estrae il contenuto del div
        $transformed_xml = new SimpleXMLElement($xsl->transformToXML($xmldoc));
        $nodes = $transformed_xml->children();
        // write values to screen
        $cnt = 0;
        foreach ($nodes as $node) {
            $cnt++;
            $atto = OppAttoPeer::retrieveByPK($node['atto_id']);
            printf("\t%d. %s => %f\n", $cnt, $atto->getTitoloCompleto(), $node['totale']);
            if ($cnt >= $n_nodes) {
                break;
            }
        }
    } catch (Exception $e) {
        printf("Errore durante la scrittura del file: %s\n", $e->getMessage());
    }
}
 public function metascore($type = "game", $name, $platform = NULL)
 {
     if (!$name) {
         throw new Exception("No parameters.");
     }
     $name = self::stripUrl($name);
     if ($platform) {
         $platform = self::stripUrl($platform);
     }
     $dom = new DomDocument();
     if ($type != ("movie" || "tv")) {
         $dom->loadHtmlFile("http://www.metacritic.com/{$type}/{$platform}/{$name}/");
         //replace this with Metacritics JSON search
     } else {
         $dom->loadHtmlFile("http://www.metacritic.com/{$type}/{$name}/");
         //replace this with Metacritics JSON search
     }
     $xpath = new DOMXpath($dom);
     $nodes = $xpath->evaluate("//span[@property='v:average']");
     if ($nodes) {
         return $nodes->item(0)->nodeValue;
     } else {
         throw new Exception("Could not find Metascore.");
     }
 }
Example #22
0
 public function buildModel($model)
 {
     try {
         $dom = new DomDocument();
         $dom->Load($this->loadModel($model));
         $rooms_base = $dom->getElementsByTagName("roomdata");
         foreach ($rooms_base as $rooms_bases) {
             $roomtypes = $rooms_bases->getElementsByTagName("roomtype")->item(0)->nodeValue;
             $caption = $rooms_bases->getElementsByTagName("caption")->item(0)->nodeValue;
             $model_name = $rooms_bases->getElementsByTagName("model_name")->item(0)->nodeValue;
             $description = $rooms_bases->getElementsByTagName("description")->item(0)->nodeValue;
             if ($this->createRooms($roomtypes, $caption, $username, $description, $model_name)) {
                 echo 'Done rooms<br/>';
             }
         }
         foreach ($dom->getElementsByTagName("roomitem") as $room_items) {
             foreach ($room_items->getElementsByTagName("item") as $item) {
                 $base_item = $item->getElementsByTagName("base_item")->item(0)->nodeValue;
                 $x = $item->getElementsByTagName("x")->item(0)->nodeValue;
                 $y = $item->getElementsByTagName("y")->item(0)->nodeValue;
                 $z = $item->getElementsByTagName("z")->item(0)->nodeValue;
                 $rot = $item->getElementsByTagName("rot")->item(0)->nodeValue;
                 $coord = array('x' => $x, 'y' => $y, 'z' => $z);
                 if ($this->addItemsToRooms($user_id, null, $base_item, $coord, $rot)) {
                     echo 'Done ' . $base_item . '<br/>';
                 }
             }
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Example #23
0
 function search($query)
 {
     $this->url .= "&q=" . urlencode($query);
     $xml = new \DomDocument();
     $xml->load($this->url);
     return $xml;
 }
Example #24
0
function process($xml)
{
    /* load xsl*/
    $filter = true;
    //remember edit on js file
    if ($filter) {
        $xmlSession = $_SESSION["process"];
        //$xmlSession = simplexml_load_string($xmlSession);
        $xml = new DOMDocument();
        $xml->loadXML($xmlSession);
        $fileXSLPath = $GLOBALS["fileXSL_process"];
        $xslDoc = new DomDocument();
        $xslDoc->load($fileXSLPath);
        //combine xsl into xml
        $proc = new XSLTProcessor();
        $proc->importStyleSheet($xslDoc);
        $xmlTrans = $proc->transformToXML($xml);
        $xmlTrans = simplexml_load_string($xmlTrans);
        $resultXml = $xmlTrans->saveXML();
        processFile($xml);
        echo $resultXml;
    } else {
        echo $xml->saveXML();
        //way 2
        //echo $xml->asXML();
    }
}
Example #25
0
 public function get_login()
 {
     $buf = $this->prefs->get('AuthMethod', 'Token');
     $token_url = $buf['url'];
     $user_node_name = $buf['user_node_name'];
     $login_attribute_name = $buf['login_attribute_name'];
     if (!isset($token_url) or $token_url == '') {
         Logger::error('main', 'Token URL is not defined');
         return NULL;
     }
     if (!isset($_REQUEST['token'])) {
         Logger::warning('main', 'Missing parameter : token');
         return NULL;
     }
     $token_url = str_replace('%TOKEN%', $_REQUEST['token'], $token_url);
     $xml = query_url($token_url);
     $dom = new DomDocument('1.0', 'utf-8');
     $ret = @$dom->loadXML($xml);
     if (!$ret) {
         Logger::error('main', 'Token webservice does not send a valid XML');
         return NULL;
     }
     $user_node = $dom->getElementsByTagname($user_node_name)->item(0);
     if (!is_object($user_node)) {
         Logger::error('main', 'Token webservice does not send a valid XML');
         return NULL;
     }
     if (!$user_node->hasAttribute($login_attribute_name)) {
         Logger::error('main', 'Token webservice does not send a valid XML');
         return NULL;
     }
     $this->login = $user_node->getAttribute($login_attribute_name);
     return $this->login;
 }
    protected function assertMatchesXpath($html, $expression, $count = 1)
    {
        $dom = new \DomDocument('UTF-8');
        try {
            // Wrap in <root> node so we can load HTML with multiple tags at
            // the top level
            $dom->loadXml('<root>'.$html.'</root>');
        } catch (\Exception $e) {
            return $this->fail(sprintf(
                "Failed loading HTML:\n\n%s\n\nError: %s",
                $html,
                $e->getMessage()
            ));
        }
        $xpath = new \DOMXPath($dom);
        $nodeList = $xpath->evaluate('/root'.$expression);

        if ($nodeList->length != $count) {
            $dom->formatOutput = true;
            $this->fail(sprintf(
                "Failed asserting that \n\n%s\n\nmatches exactly %s. Matches %s in \n\n%s",
                $expression,
                $count == 1 ? 'once' : $count . ' times',
                $nodeList->length == 1 ? 'once' : $nodeList->length . ' times',
                // strip away <root> and </root>
                substr($dom->saveHTML(), 6, -8)
            ));
        }
    }
Example #27
0
function parse_session_status_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $node = $dom->getElementsByTagname('session')->item(0);
    if (is_null($node)) {
        return false;
    }
    if (!$node->hasAttribute('id')) {
        return false;
    }
    if (!$node->hasAttribute('status')) {
        return false;
    }
    $ret = array('id' => $node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $node->getAttribute('status'), 'reason' => NULL, 'role' => NULL);
    if ($node->hasAttribute('reason')) {
        $ret['reason'] = $node->getAttribute('reason');
    }
    if ($node->hasAttribute('role')) {
        $ret['role'] = $node->getAttribute('role');
    }
    return $ret;
}
 function xslt_process($xsltproc, $xml_arg, $xsl_arg, $xslcontainer = null, $args = null, $params = null)
 {
     // Create instances of the DomDocument class
     $xml = new DomDocument();
     $xsl = new DomDocument();
     // Load the xml document and the xsl template
     $xml->load($xml_arg);
     $xsl->load($xsl_arg);
     // Load the xsl template
     $xsltproc->importStyleSheet($xsl);
     // Set parameters when defined
     if ($params) {
         foreach ($params as $param => $value) {
             $xsltproc->setParameter("", $param, $value);
         }
     }
     // Start the transformation
     $processed = $xsltproc->transformToXML($xml);
     // Put the result in a file when specified
     if ($xslcontainer) {
         return file_put_contents($xslcontainer, $processed);
     } else {
         return $processed;
     }
 }
 public function call_success()
 {
     global $USER, $COURSE, $CFG;
     if (empty($this->_xmlresponse)) {
         if (is_siteadmin($USER->id)) {
             notice(get_string('adminemptyxml', 'adobeconnect'), $CFG->wwwroot . '/admin/settings.php?section=modsettingadobeconnect');
         } else {
             notice(get_string('emptyxml', 'adobeconnect'), '', $COURSE);
         }
     }
     $dom = new DomDocument();
     $dom->loadXML($this->_xmlresponse);
     $domnodelist = $dom->getElementsByTagName('status');
     if ($domnodelist->item(0)->hasAttributes()) {
         $domnode = $domnodelist->item(0)->attributes->getNamedItem('code');
         if (!is_null($domnode)) {
             if (0 == strcmp('ok', $domnode->nodeValue)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #30
-1
 function __doRequest($request, $location, $action, $version)
 {
     $dom = new DomDocument('1.0', 'UTF-8');
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($request);
     $hdr = $dom->createElement('soapenv:Header');
     $secNode = $dom->createElement("wsse:Security");
     $secNode->setAttribute("soapenv:mustUnderstand", "1");
     $secNode->setAttribute("xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
     $usernameTokenNode = $dom->createElement("wsse:UsernameToken");
     $usernameTokenNode->setAttribute("wsu:Id", "UsernameToken-1");
     $usernameTokenNode->setAttribute("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
     $usrNode = $dom->createElement("wsse:Username");
     $usrNode->appendChild($dom->createTextNode(WS_USER));
     $pwdNode = $dom->createElement("wsse:Password");
     $pwdNode->setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
     $pwdNode->appendchild($dom->createTextnode(WS_PWD));
     $usernameTokenNode->appendChild($usrNode);
     $usernameTokenNode->appendChild($pwdNode);
     $secNode->appendChild($usernameTokenNode);
     $hdr->appendChild($secNode);
     $dom->documentElement->insertBefore($hdr, $dom->documentElement->firstChild);
     $request = $dom->saveXML();
     $request = str_replace("SOAP-ENV", "soapenv", $request);
     $request = str_replace("ns1", "cgt", $request);
     $request = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $request);
     //  echo "Este es el nuevo XML: " . print_r($request, true);
     return parent::__doRequest($request, $location, $action, $version);
 }