/**
  *
  * Convert the $source string into a array.
  * This array should always respect the scheme defined by the
  * getDataFromSource method of the ServiceDriver
  * @param string $source
  * @return string
  */
 public function createArray($source, $driver, $url, &$errorFlag)
 {
     // trying to load XML into DOM Document
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     $doc->formatOutput = false;
     // ignore errors, but save it if was successful
     $errorFlag = !@$doc->loadXML($source);
     if (!$errorFlag) {
         $xml['xml'] = @$doc->saveXML();
         if ($xml['xml'] === FALSE) {
             $errorFlag = true;
         } else {
             // add id to array
             $idTagName = $driver->getIdTagName();
             if ($idTagName == null) {
                 $xml['id'] = Lang::createHandle($url);
             } else {
                 $xml['id'] = $doc->getElementsByTagName($idTagName)->item(0)->nodeValue;
             }
             $xml['title'] = $doc->getElementsByTagName($driver->getTitleTagName())->item(0)->nodeValue;
             $xml['thumb'] = $doc->getElementsByTagName($driver->getThumbnailTagName())->item(0)->nodeValue;
         }
     }
     if ($errorFlag) {
         // return error message
         $xml['error'] = __('Symphony could not parse XML from oEmbed remote service');
     }
     return $xml;
 }
Example #2
0
 public function loadRulesFromDom()
 {
     $styles = $this->dom->getElementsByTagName('style');
     foreach ($styles as $style_node) {
         $this->rules = array_merge($this->rules, self::parse($style_node->nodeValue));
     }
 }
 public static function listParties()
 {
     $doc = new DOMDocument();
     $doc->load(self::parties);
     $codes = $doc->getElementsByTagName("Codigo");
     $names = $doc->getElementsByTagName("Nombre");
     //return value structure
     $listParties = array();
     $codeArray = array();
     $nameArray = array();
     //main information array
     foreach ($codes as $node) {
         array_push($codeArray, $node->nodeValue);
     }
     foreach ($names as $node) {
         array_push($nameArray, $node->nodeValue);
     }
     for ($i = 0; $i < count($codeArray); $i++) {
         $code = $codeArray[$i];
         $name = $nameArray[$i];
         $account = new Account($code, $name);
         array_push($listParties, $account);
     }
     return $listParties;
 }
Example #4
0
 public function getPlayerRssfeed($playername)
 {
     $returnArray = [];
     $xml = "https://news.google.de/news/feeds?pz=1&cf=all&ned=LANGUAGE&hl=aus&q=" . $playername . "&output=rss";
     $xmlDoc = new \DOMDocument();
     $xmlDoc->load($xml);
     // get elements from "<channel>"
     $channel = $xmlDoc->getElementsByTagName('channel')->item(0);
     $returnArray['feed_title'] = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
     $returnArray['feed_link'] = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
     $returnArray['feed_desc'] = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
     $items = $xmlDoc->getElementsByTagName('channel')->item(0)->getElementsByTagName('item');
     foreach ($items as $key => $item) {
         $title = $item->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
         $description = $item->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
         $pubDate = $item->getElementsByTagName('pubDate')->item(0)->firstChild->nodeValue;
         $guid = $item->getElementsByTagName('guid')->item(0)->firstChild->nodeValue;
         $returnArray['item'][$key]['title'] = $title;
         $returnArray['item'][$key]['pubdate'] = $pubDate;
         /*
          * $returnArray['item'][$key]['description'] = $description;
          * $returnArray['item'][$key]['pubdate'] = $pubDate;
          * $returnArray['item'][$key]['guid'] = $guid;
          */
     }
     return $returnArray;
 }
Example #5
0
function changeApplicationXmlVersions($file, $versionNum, $subver)
{
    $verStr = $versionNum . "_" . $subver;
    $newFiles = getNewFileName();
    $doc = new DOMDocument();
    $doc->load($file);
    $assests = $doc->getElementsByTagName("asset");
    $modules = $doc->getElementsByTagName("module");
    foreach ($newFiles as $nfi) {
        foreach ($assests as $ai) {
            $src = $ai->getAttribute("src");
            if (strpos($src, $nfi) !== false) {
                //echo "ok<br />";
                $ai->setAttribute("version", $verStr);
            }
            $src = $ai->nodeValue;
            if (strpos($src, $nfi) !== false) {
                $ai->setAttribute("version", $verStr);
                //echo "ok<br />";
            }
        }
        foreach ($modules as $mi) {
            $src = $mi->getAttribute("src");
            if (strpos($src, $nfi) !== false) {
                $mi->setAttribute("version", $verStr);
                //echo "ok  $nfi<br />";
            }
        }
    }
    $doc->save($file);
}
Example #6
0
 function getMeta($url)
 {
     $cache = $this->cache->getPageMeta($url);
     if (!empty($cache)) {
         return $cache;
     }
     $html = $this->file_get_contents_curl($url);
     $doc = new \DOMDocument();
     @$doc->loadHTML($html);
     $nodes = $doc->getElementsByTagName('title');
     $title = $nodes->item(0)->nodeValue;
     $metas = $doc->getElementsByTagName('meta');
     $values = array('title' => $title);
     for ($i = 0; $i < $metas->length; $i++) {
         $meta = $metas->item($i);
         $id = $meta->getAttribute('name');
         if (empty($id)) {
             $id = $meta->getAttribute('property');
         }
         if (!empty($id)) {
             $values[$id] = $meta->getAttribute('content');
         }
     }
     $this->cache->storePageMeta($url, $values);
     return $values;
 }
Example #7
0
 function update()
 {
     // Cree un objet pour accueillir le contenu du RSS : un document XML
     $doc = new DOMDocument();
     //Telecharge le fichier XML dans $rss
     $doc->load($this->url);
     // Recupère la liste (DOMNodeList) de tous les elements de l'arbre 'title'
     $nodeList = $doc->getElementsByTagName('title');
     // Met à jour le titre dans l'objet
     $this->titre = $nodeList->item(0)->textContent;
     // Recupère la liste de toutes les dates
     $nodeList = $doc->getElementsByTagName('pubDate');
     //Met à jour la date dans l'objet
     $this->date = $nodeList->item(0)->textContent;
     //recupère la liste des url
     $nodeList = $doc->getElementsByTagName('link');
     //met à jour la date dans l'objet
     $this->url = $nodeList->item(0)->textContent;
     //met à jour l'image de l'objet
     $nodeList = $doc->getElementsByTagName('enclosure');
     $this->enclosure = $nodeList->item(0)->textContent;
     $nomLocalImage = 1;
     // Recupère tous les items du flux RSS
     foreach ($doc->getElementsByTagName('item') as $node) {
         $nouvelle = new Nouvelle();
         // Met à jour la nouvelle avec l'information téléchargée
         $nouvelle->update($node);
         // Télécharge l'image
         $nouvelle->downloadImage($node, $nomLocalImage);
         // on ajoute la nouvelle courante a la liste
         $this->nouvelles[] = $nouvelle;
     }
 }
 public function parse($html)
 {
     if (empty($html)) {
         $this->title = $this->message = 'Empty exception';
         $this->sourceFile = '';
         return false;
     }
     if (!$this->domDocument) {
         $this->domDocument = new \DOMDocument();
     }
     @$this->domDocument->loadHTML($html);
     $titleItem = $this->domDocument->getElementsByTagName("title")->item(0);
     $this->title = $titleItem ? $titleItem->textContent : 'N/A';
     try {
         $sourceFileElement = $this->domDocument->getElementById("tracy-bs-error");
         if (is_object($sourceFileElement)) {
             $sourceFileLinkNode = $sourceFileElement->getElementsByTagName("a")->item(0);
             $this->sourceFile = trim($sourceFileLinkNode->textContent);
         } else {
             $this->sourceFile = 'Unknown format of exception';
         }
         $messageNode = $this->domDocument->getElementsByTagName("p")->item(0);
         if (is_object($messageNode)) {
             $messageNode->removeChild($messageNode->lastChild);
             $this->message = trim($messageNode->textContent);
         } else {
             $this->message = 'Unable to parse';
         }
     } catch (\Exception $e) {
         $this->message = 'Unable to parse';
     }
 }
Example #9
0
 public static function getVideoData($videoid, $customimage, $customtitle, $customdescription)
 {
     $theTitle = '';
     $Description = '';
     $theImage = '';
     $videodata = array();
     if (phpversion() < 5) {
         return "Update to PHP 5+";
     }
     try {
         $url = 'http://api.own3d.tv/rest/video/list.xml?videoid=' . $videoid;
         $htmlcode = YouTubeGalleryMisc::getURLData($url);
         if (strpos($htmlcode, '<?xml version') === false) {
             $pair = array('Invalid id', 'Invalid id', '', '0', '0', '0', '0', '0', '0', '0', '');
             return $pair;
         }
         $doc = new DOMDocument();
         $doc->loadXML($htmlcode);
         $video_thumb_file_small = 'http://owned.vo.llnwd.net/v1/static/static/images/thumbnails/tn_' . $videoid . '__1.jpg';
         $videodata = array('videosource' => 'own3dtvvideo', 'videoid' => $videoid, 'imageurl' => $video_thumb_file_small, 'title' => $doc->getElementsByTagName("video_name")->item(0)->nodeValue, 'description' => $doc->getElementsByTagName("video_description")->item(0)->nodeValue, 'publisheddate' => "", 'duration' => $doc->getElementsByTagName("video_duration")->item(0)->nodeValue, 'rating_average' => 0, 'rating_max' => 0, 'rating_min' => 0, 'rating_numRaters' => 0, 'statistics_favoriteCount' => 0, 'statistics_viewCount' => $doc->getElementsByTagName("video_views_total")->item(0)->nodeValue, 'keywords' => '');
         return $videodata;
     } catch (Exception $e) {
         return 'cannot get youtube video data';
     }
     return array('videosource' => 'own3dtvvideo', 'videoid' => $videoid, 'imageurl' => $theImage, 'title' => $theTitle, 'description' => $Description);
 }
Example #10
0
 public function process($xml)
 {
     $this->step = 0;
     $xml = $this->preprocessXml($xml);
     $xml = $this->handleSimpleSnippets($xml);
     // Add a snippet to trigger a process
     $snippetCount = count($this->parseSnippetsInString($xml));
     if ($snippetCount == 0) {
         $xml .= "<filler>[str_replace('a','b','c')]</filler>";
     }
     // While we have snippets
     while ($snippetCount = count($this->parseSnippetsInString($xml))) {
         $this->step++;
         $xml = '<root>' . $xml . '</root>';
         $this->initVariables($xml);
         $root = $this->dom->getElementsByTagName("root");
         $this->dom->recover = true;
         $this->parseElement($root->item(0));
         $this->dom->preserveWhiteSpace = false;
         $this->dom->formatOutput = true;
         $response = $this->dom->saveXML($this->dom);
         $xml = $this->cleanResponse($xml, $response);
         if ($this->step > 8) {
             throw new WpaeTooMuchRecursionException('Too much recursion');
         }
     }
     $xml = $this->postProcessXml($xml);
     $xml = $this->decodeSpecialCharacters($xml);
     $xml = $this->encodeSpecialCharsInAttributes($xml);
     return $xml;
 }
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         case 'parsexml':
             $firstParam = $namedParameters['first_param'];
             if (trim($operatorValue) != '') {
                 $dom = new DOMDocument('1.0', 'utf-8');
                 if ($dom->loadXML($operatorValue)) {
                     $FileAttributeValue = $dom->getElementsByTagName($firstParam)->item(0)->textContent;
                     if (!$FileAttributeValue) {
                         $FileAttributeValue = $dom->getElementsByTagName($firstParam)->item(0)->getAttribute('value');
                     }
                 }
                 $operatorValue = $FileAttributeValue;
             }
             break;
         case 'filecheck':
             if (trim($operatorValue) != '') {
                 $dom = new DOMDocument('1.0', 'utf-8');
                 if ($dom->loadXML($operatorValue)) {
                     $FileAttributeValue = $dom->getElementsByTagName('Filename')->item(0)->textContent;
                     if (!$FileAttributeValue) {
                         $FileAttributeValue = $dom->getElementsByTagName('Filename')->item(0)->getAttribute('value');
                     }
                 }
                 if (file_exists(eZSys::wwwDir() . $FileAttributeValue)) {
                     $operatorValue = true;
                 } else {
                     $operatorValue = false;
                 }
             }
             break;
     }
 }
Example #12
0
 public function actionNotifyalipay()
 {
     $user_id = Yii::app()->user->id;
     $alipay = Yii::app()->alipay;
     $verify_result = $alipay->verifyNotify();
     if ($verify_result) {
         $doc = new DOMDocument();
         $doc->loadXML($notify_data);
         if (!empty($doc->getElementsByTagName("notify")->item(0)->nodeValue)) {
             //商户订单号
             $out_trade_no = $doc->getElementsByTagName("out_trade_no")->item(0)->nodeValue;
             //支付宝交易号
             $trade_no = $doc->getElementsByTagName("trade_no")->item(0)->nodeValue;
             //交易状态
             $trade_status = $doc->getElementsByTagName("trade_status")->item(0)->nodeValue;
             //接口示例文件中,下面用的$_POST['trade_status'],但是我用POST获取不到值,直接用上面取出的$trade_status也可以。
             if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') {
                 //判断该订单是否已处理
                 //处理业务逻辑
                 echo 'success';
             }
         }
     } else {
         echo 'fail';
     }
 }
Example #13
0
 public function XmlAuthResponse($responseXml)
 {
     $doc = new DOMDocument();
     $doc->loadXML($responseXml);
     try {
         if (strpos($responseXml, "ERROR")) {
             $responseNodes = $doc->getElementsByTagName("ERROR");
             foreach ($responseNodes as $node) {
                 $this->errorString = $node->getElementsByTagName('ERRORSTRING')->item(0)->nodeValue;
             }
             $this->isError = true;
         } else {
             if (strpos($responseXml, "PAYMENTRESPONSE")) {
                 $responseNodes = $doc->getElementsByTagName("PAYMENTRESPONSE");
                 foreach ($responseNodes as $node) {
                     $this->uniqueRef = $node->getElementsByTagName('UNIQUEREF')->item(0)->nodeValue;
                     $this->responseCode = $node->getElementsByTagName('RESPONSECODE')->item(0)->nodeValue;
                     $this->responseText = $node->getElementsByTagName('RESPONSETEXT')->item(0)->nodeValue;
                     $this->approvalCode = $node->getElementsByTagName('APPROVALCODE')->item(0)->nodeValue;
                     $this->authorizedAmount = $node->getElementsByTagName('AUTHORIZEDAMOUNT')->item(0)->nodeValue;
                     $this->dateTime = $node->getElementsByTagName('DATETIME')->item(0)->nodeValue;
                     $this->avsResponse = $node->getElementsByTagName('AVSRESPONSE')->item(0)->nodeValue;
                     $this->cvvResponse = $node->getElementsByTagName('CVVRESPONSE')->item(0)->nodeValue;
                     $this->hash = $node->getElementsByTagName('HASH')->item(0)->nodeValue;
                 }
             } else {
                 throw new Exception("Invalid Response");
             }
         }
     } catch (Exception $e) {
         $this->isError = true;
         $this->errorString = $e->getMessage();
     }
 }
Example #14
0
 public function testCreate()
 {
     $crawler = $this->client->request('GET', $this->getUrl('orocrm_sales_lead_create'));
     /** @var Form $form */
     $form = $crawler->selectButton('Save and Close')->form();
     $name = 'name' . $this->generateRandomString();
     $form['orocrm_sales_lead_form[name]'] = $name;
     $form['orocrm_sales_lead_form[firstName]'] = 'firstName';
     $form['orocrm_sales_lead_form[lastName]'] = 'lastName';
     $form['orocrm_sales_lead_form[address][city]'] = 'City Name';
     $form['orocrm_sales_lead_form[address][label]'] = 'Main Address';
     $form['orocrm_sales_lead_form[address][postalCode]'] = '10000';
     $form['orocrm_sales_lead_form[address][street2]'] = 'Second Street';
     $form['orocrm_sales_lead_form[address][street]'] = 'Main Street';
     $form['orocrm_sales_lead_form[companyName]'] = 'Company';
     $form['orocrm_sales_lead_form[email]'] = '*****@*****.**';
     $form['orocrm_sales_lead_form[owner]'] = 1;
     $form['orocrm_sales_lead_form[dataChannel]'] = $this->getReference('default_channel')->getId();
     $doc = new \DOMDocument("1.0");
     $doc->loadHTML('<select name="orocrm_sales_lead_form[address][country]" id="orocrm_sales_lead_form_address_country" ' . 'tabindex="-1" class="select2-offscreen"> ' . '<option value="" selected="selected"></option> ' . '<option value="US">United States</option> </select>');
     $field = new ChoiceFormField($doc->getElementsByTagName('select')->item(0));
     $form->set($field);
     $doc->loadHTML('<select name="orocrm_sales_lead_form[address][region]" id="orocrm_sales_lead_form_address_region" ' . 'tabindex="-1" class="select2-offscreen"> ' . '<option value="" selected="selected"></option> ' . '<option value="US-CA">California</option> </select>');
     $field = new ChoiceFormField($doc->getElementsByTagName('select')->item(0));
     $form->set($field);
     $form['orocrm_sales_lead_form[address][country]'] = 'US';
     $form['orocrm_sales_lead_form[address][region]'] = 'US-CA';
     $this->client->followRedirects(true);
     $crawler = $this->client->submit($form);
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $this->assertContains("Lead saved", $crawler->html());
     return $name;
 }
function rsky_modify_link_posts($data)
{
    //Get content
    $dom = new DOMDocument();
    $dom->loadHTML($data);
    foreach ($dom->getElementsByTagName('a') as $node) {
        if ($node->hasAttribute('href')) {
            if (!$node->hasAttribute('title')) {
                $url = $node->getAttribute('href')->textContent;
                $url = esc_url_raw(trim($url, '"'));
                $args = array('sslverify' => false);
                $webpage = wp_remote_get($url);
                if (!is_wp_error($webpage)) {
                    if (wp_remote_retrieve_response_code($webpage) === 200 && ($body = wp_remote_retrieve_body($webpage))) {
                        $remote_dom = new DOMDocument();
                        $remote_dom->loadHTML($body);
                        $title = $dom->getElementsByTagName('title');
                        if ($title->length > 0) {
                            $node->setAttribute('title', $title->item(0)->textContent);
                        }
                    }
                }
            }
        }
    }
    $data = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace(array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML()));
    return $data;
}
 /**
  * [getCapData description]
  */
 public static function getCapData()
 {
     // API Key
     $key = Config::inst()->get('AbcTextCap', 'text_captcha_api_key');
     if (!$key) {
         $key = uniqid();
     }
     // try to use the text captcha service
     $response = file_get_contents('http://api.textcaptcha.com/' . $key . '.xml');
     if ($response) {
         $document = new DOMDocument();
         if ($document->loadXML($response)) {
             $data = (object) array('q' => $entries = $document->getElementsByTagName('question')->item(0)->nodeValue, 'a' => array());
             $answers = $document->getElementsByTagName('answer');
             foreach ($answers as $a) {
                 $data->a[] = $a->nodeValue;
             }
         }
     }
     // fall back to the internal "database" of questions
     if (empty($data->q) || empty($data->a) || Session::get("AbcTextCap") && $data->q == Session::get("AbcTextCap")->q) {
         $data = (object) AbcTextCapData::getChallenge();
         $as = array();
         foreach ($data->a as $a) {
             $as[] = md5(strtolower(trim($a)));
         }
         $data->a = $as;
     }
     // save the cap data
     Session::set("AbcTextCap", $data);
     // return
     return $data;
 }
Example #17
0
 public function getipinfo()
 {
     $ip = JFactory::getApplication()->input->get('ip');
     if (!empty($ip)) {
         header('Content-type: text/plain; charset=utf8');
         $xml_file = 'http://api.sypexgeo.net/xml/' . $ip;
         $xml_object = new DOMDocument();
         $xml_object->load($xml_file);
         $arCityInfo = array();
         $country_id = $xml_object->getElementsByTagName('city')->item(0)->getElementsByTagName('country_id')->item(0)->nodeValue;
         if (isset($country_id) && $country_id == 0) {
             // не определено по IP
             $arCityInfo['unknown_ip'] = JText::_('COM_DOWNFILES_GEO_NOT_DETERMINED');
         } else {
             $elem_country = $xml_object->getElementsByTagName('country')->item(0)->getElementsByTagName('name_ru');
             $elem_city = $xml_object->getElementsByTagName('city')->item(0)->getElementsByTagName('name_ru');
             $elem_lat = $xml_object->getElementsByTagName('city')->item(0)->getElementsByTagName('lat');
             $elem_lng = $xml_object->getElementsByTagName('city')->item(0)->getElementsByTagName('lon');
             $arCityInfo['country'] = $elem_country->item(0)->nodeValue;
             $arCityInfo['city'] = $elem_city->item(0)->nodeValue;
             $arCityInfo['lat'] = $elem_lat->item(0)->nodeValue;
             $arCityInfo['lon'] = $elem_lng->item(0)->nodeValue;
         }
         echo json_encode($arCityInfo);
         die;
     } else {
         return false;
     }
 }
 public static function map($response)
 {
     $responseDOM = new \DOMDocument();
     $responseDOM->loadXML($response);
     $purchaseInvoiceTags = array('date' => 'setDate', 'duedate' => 'setDueDate', 'inputdate' => 'setInputDate', 'invoicenumber' => 'setInvoiceNumber', 'modificationdate' => 'setModificationDate', 'number' => 'setNumber', 'origin' => 'setOrigin', 'originreference' => 'setOriginReference', 'period' => 'setPeriod', 'regime' => 'setRegime');
     $purchaseInvoice = new PurchaseInvoice();
     foreach ($purchaseInvoiceTags as $tag => $method) {
         $_tag = $responseDOM->getElementsByTagName($tag)->item(0);
         if (isset($_tag) && isset($_tag->textContent)) {
             $purchaseInvoice->{$method}($_tag->textContent);
         }
     }
     $currencyTag = $responseDOM->getElementsByTagName('currency')->item(0);
     if (isset($currencyTag)) {
         $currency = new Currency();
         $currency->setCode($currencyTag->textContent);
         $currency->setName($currencyTag->attributes->getNamedItem('name')->textContent);
         $currency->setShortName($currencyTag->attributes->getNamedItem('shortname')->textContent);
         $purchaseInvoice->setCurrency($currency);
     }
     $userTag = $responseDOM->getElementsByTagName('user')->item(0);
     if (isset($userTag)) {
         $user = new User();
         $user->setCode($userTag->textContent);
         $user->setName($userTag->attributes->getNamedItem('name')->textContent);
         $user->setShortName($userTag->attributes->getNamedItem('shortname')->textContent);
         $purchaseInvoice->setUser($user);
     }
     return $purchaseInvoice;
 }
Example #19
0
function chkHASH($file)
{
    if (!is_file($file)) {
        return false;
    }
    $docxml = file_get_contents($file);
    // carrega o documento no DOM
    $xmldoc = new DOMDocument();
    $xmldoc->preservWhiteSpace = false;
    //elimina espaços em branco
    $xmldoc->formatOutput = false;
    // muito importante deixar ativadas as opçoes para limpar os espacos em branco
    // e as tags vazias
    $xmldoc->loadXML($docxml, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
    //extrair a tag com os dados a serem assinados
    $node = $xmldoc->getElementsByTagName('infNFe')->item(0);
    $digInfo = $xmldoc->getElementsByTagName('DigestValue')->item(0)->nodeValue;
    //extrai os dados da tag para uma string
    $dados = $node->C14N(false, false, NULL, NULL);
    //calcular o hash dos dados
    $hashValue = hash('sha1', $dados, true);
    //converte o valor para base64 para serem colocados no xml
    $digValue = base64_encode($hashValue);
    return 'Digest Calculado: ' . $digValue . '<BR>Digest da NFe: ' . $digInfo;
}
 public function html_to_html($html)
 {
     $dom = new DOMDocument();
     if (is_file($html)) {
         $dom->loadHTMLFile($html);
     } else {
         $dom->loadHTML($html);
     }
     $section_title = $dom->getElementsByTagName('html')->item(0)->getElementsByTagName('head')->item(0)->nodeValue;
     $section_li_a = $this->dom->createElement('a', $section_title);
     $section_li_a->setAttribute('href', '#' . str_replace(' ', null, $section_title));
     $section_li = $this->dom->createElement('li');
     $section_li->appendChild($section_li_a);
     $this->section_list->appendChild($section_li);
     $p = $this->dom->createElement('hr');
     $p->setAttribute('style', 'height: 50px; border: 0;');
     $this->dom_body->appendChild($p);
     $p = $this->dom->createElement('a');
     $p->setAttribute('name', str_replace(' ', null, $section_title));
     $this->dom_body->appendChild($p);
     $p = $this->dom->createElement('h1', $section_title);
     $this->dom_body->appendChild($p);
     // TODO: the below code is known to emit a fatal error right now since the nodes are different, need to copy/merge nodes between docs
     foreach ($dom->getElementsByTagName('html')->item(0)->getElementsByTagName('body')->item(0)->childNodes as $node) {
         $n = $this->dom->importNode($node, true);
         $this->dom_body->appendChild($n);
     }
 }
Example #21
0
 /**
  * Parse config file.
  *
  * Return:
  * <code>
  * {
  *   namespace: string,
  *   directory: string
  * }
  * </code>
  *
  * @param string $file
  *
  * @return array
  */
 protected function parseConfig($file)
 {
     $namespace = '';
     $directory = '';
     $config = file_get_contents($file);
     switch (pathinfo($file, PATHINFO_EXTENSION)) {
         case 'yml':
         case 'yaml':
             $config = Yaml::parse($config);
             if (isset($config['migrations_namespace'])) {
                 $namespace = $config['migrations_namespace'];
             }
             if (isset($config['migrations_directory'])) {
                 $directory = $config['migrations_directory'];
             }
             break;
         case 'xml':
             $doc = new \DOMDocument();
             $doc->loadXML($config);
             $list = $doc->getElementsByTagName('migrations-namespace');
             if ($list->length) {
                 $namespace = $list->item(0)->nodeValue;
             }
             $list = $doc->getElementsByTagName('migrations-directory');
             if ($list->length) {
                 $directory = $list->item(0)->nodeValue;
             }
             break;
     }
     return ['namespace' => $namespace && $namespace[0] == '\\' ? substr($namespace, 1) : $namespace, 'directory' => $directory];
 }
Example #22
0
 private function render(\DOMDocument $doc, Element $element, $parent = null)
 {
     if ($element instanceof \tarcisio\svg\SVG) {
         $svgs = $doc->getElementsByTagName('svg');
         $svg = $svgs->item(0);
         $svg->setAttribute('width', $element->width);
         $svg->setAttribute('height', $element->height);
         $svg->setAttribute('viewBox', "0 0 {$element->width} {$element->height}");
         $gs = $doc->getElementsByTagName('g');
         $g = $gs->item(0);
         foreach ($element->getChildren() as $ch) {
             $this->render($doc, $ch, $g);
         }
         return $doc;
     }
     if (!is_null($element->getTitle())) {
         $element->appendChild(new Title('', $element->getTitle()));
     }
     $e = $doc->createElement($element->getElementName());
     $parent->appendChild($e);
     foreach ($element->getAttributes() as $k => $v) {
         if (!is_null($v)) {
             $e->setAttribute($k, $v);
         }
     }
     if (!is_null($element->getValue())) {
         $e->nodeValue = $element->getValue();
     }
     foreach ($element->getChildren() as $ch) {
         $this->render($doc, $ch, $e);
     }
     return $doc;
 }
 function accountInformation($order)
 {
     $firstName = '';
     $lastName = '';
     $email = '';
     $address = '';
     $dom = new DOMDocument('1.0', 'utf-8');
     $xmlString = $order->attribute('data_text_1');
     if ($xmlString != null) {
         $dom = new DOMDocument('1.0', 'utf-8');
         $success = $dom->loadXML($xmlString);
         $firstNameNode = $dom->getElementsByTagName('first-name')->item(0);
         if ($firstNameNode) {
             $firstName = $firstNameNode->textContent;
         }
         $lastNameNode = $dom->getElementsByTagName('last-name')->item(0);
         if ($lastNameNode) {
             $lastName = $lastNameNode->textContent;
         }
         $emailNode = $dom->getElementsByTagName('email')->item(0);
         if ($emailNode) {
             $email = $emailNode->textContent;
         }
         $addressNode = $dom->getElementsByTagName('address')->item(0);
         if ($addressNode) {
             $address = $addressNode->textContent;
         }
     }
     return array('first_name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'address' => $address);
 }
Example #24
0
 /**
  * Convert dom node tree to array
  *
  * @param \DOMDocument $source
  * @return array
  */
 public function convert($source)
 {
     $result = ['renderers' => [], 'totals' => []];
     $pageTypes = $source->getElementsByTagName('page');
     foreach ($pageTypes as $pageType) {
         /** @var \DOMNode $pageType */
         $pageTypeName = $pageType->attributes->getNamedItem('type')->nodeValue;
         foreach ($pageType->childNodes as $rendererNode) {
             /** @var \DOMNode $rendererNode */
             if ($rendererNode->nodeType != XML_ELEMENT_NODE) {
                 continue;
             }
             $productType = $rendererNode->attributes->getNamedItem('product_type')->nodeValue;
             $result['renderers'][$pageTypeName][$productType] = $rendererNode->nodeValue;
         }
     }
     $totalItems = $source->getElementsByTagName('total');
     foreach ($totalItems as $item) {
         /** @var \DOMNode $item */
         $itemName = $item->attributes->getNamedItem('name')->nodeValue;
         foreach ($item->childNodes as $setting) {
             /** @var \DOMNode $setting */
             if ($setting->nodeType != XML_ELEMENT_NODE) {
                 continue;
             }
             $result['totals'][$itemName][$setting->nodeName] = $setting->nodeValue;
         }
     }
     return $result;
 }
 /**
  * Setup scripts.
  *
  * @param ReportRouting $reportRouting
  */
 protected function setScripts(ReportRouting $reportRouting)
 {
     $report = $reportRouting->getReport();
     $scripts = $report->getScripts();
     $content = $report->getResponse();
     $doc = new \DOMDocument();
     $doc->loadHTML($content);
     $heads = $doc->getElementsByTagName('head');
     if ($heads->length == 0) {
         /* If no head is created, add it at the top of HTML */
         $head = $doc->createElement('head');
         $html = $doc->getElementsByTagName('html');
         $html->item(0)->insertBefore($head, $html->item(0)->firstChild);
     } else {
         $head = $heads->item(0);
     }
     foreach ($scripts as $script) {
         $url = $reportRouting->getUrl($script);
         $element = $doc->createElement('script');
         $element->setAttribute('type', 'text/javascript');
         $element->setAttribute('src', $url);
         $head->appendChild($element);
     }
     $report->setResponse($doc->saveHTML());
 }
Example #26
0
function checkSitemap($url)
{
    $count = 0;
    try {
        $xml = pullXML($url);
        $doc = new DOMDocument('1.0', 'UTF-8');
        $doc->loadXML($xml);
        // Check if we have a sitemap index
        $sitemaps = $doc->getElementsByTagName('sitemap');
        foreach ($sitemaps as $elem) {
            $newurl = $elem->getElementsByTagName('loc')->item(0)->nodeValue;
            $count += checkSitemap($newurl);
        }
        // If not, treat it like a real sitemap
        if (!$count) {
            $locs = $doc->getElementsByTagName('loc');
            foreach ($locs as $node) {
                $count++;
            }
        }
    } catch (Exception $e) {
        $count = 0;
    }
    return $count;
}
Example #27
0
 /**
  * Transform asset paths based on the report
  *
  * @param $content
  * @return string
  * @throws ExtensionNotLoadedException
  */
 public function transformAssetPaths($content)
 {
     if (null === $content) {
         throw new ContentNotFoundException('No content was found to be rendered');
     }
     libxml_use_internal_errors(true);
     $doc = new \DOMDocument();
     $doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES'));
     $reportRouting = $this->extensionManager->findExtension('report_routing');
     if (null === $reportRouting) {
         throw new ExtensionNotLoadedException('report_routing');
     }
     /* Transform images */
     $images = $doc->getElementsByTagName('img');
     foreach ($images as $image) {
         $this->prepareAsset($image, 'src', $reportRouting);
     }
     /* Transform styles */
     $styles = $doc->getElementsByTagName('link');
     foreach ($styles as $style) {
         $this->prepareAsset($style, 'href', $reportRouting);
     }
     /* Transform scripts */
     $scripts = $doc->getElementsByTagName('script');
     foreach ($scripts as $script) {
         $this->prepareAsset($script, 'src', $reportRouting);
     }
     return $doc->saveHTML();
 }
 function accountInformation($order)
 {
     $firstName = '';
     $lastName = '';
     $email = '';
     $street1 = '';
     $street2 = '';
     $zip = '';
     $place = '';
     $country = '';
     $comment = '';
     $state = '';
     $dom = new DOMDocument('1.0', 'utf-8');
     $xmlString = $order->attribute('data_text_1');
     if ($xmlString != null) {
         $dom = new DOMDocument('1.0', 'utf-8');
         $success = $dom->loadXML($xmlString);
         $firstNameNode = $dom->getElementsByTagName('first-name')->item(0);
         if ($firstNameNode) {
             $firstName = $firstNameNode->textContent;
         }
         $lastNameNode = $dom->getElementsByTagName('last-name')->item(0);
         if ($lastNameNode) {
             $lastName = $lastNameNode->textContent;
         }
         $emailNode = $dom->getElementsByTagName('email')->item(0);
         if ($emailNode) {
             $email = $emailNode->textContent;
         }
         $street1Node = $dom->getElementsByTagName('street1')->item(0);
         if ($street1Node) {
             $street1 = $street1Node->textContent;
         }
         $street2Node = $dom->getElementsByTagName('street2')->item(0);
         if ($street2Node) {
             $street2 = $street2Node->textContent;
         }
         $zipNode = $dom->getElementsByTagName('zip')->item(0);
         if ($zipNode) {
             $zip = $zipNode->textContent;
         }
         $placeNode = $dom->getElementsByTagName('place')->item(0);
         if ($placeNode) {
             $place = $placeNode->textContent;
         }
         $stateNode = $dom->getElementsByTagName('state')->item(0);
         if ($stateNode) {
             $state = $stateNode->textContent;
         }
         $countryNode = $dom->getElementsByTagName('country')->item(0);
         if ($countryNode) {
             $country = $countryNode->textContent;
         }
         $commentNode = $dom->getElementsByTagName('comment')->item(0);
         if ($commentNode) {
             $comment = $commentNode->textContent;
         }
     }
     return array('first_name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'street1' => $street1, 'street2' => $street2, 'zip' => $zip, 'place' => $place, 'state' => $state, 'country' => $country, 'comment' => $comment);
 }
Example #29
0
 function init($csl, $lang)
 {
     // define field values appropriate to your data in the csl_mapper class and un-comment the next line.
     $this->mapper = new csl_mapper();
     $this->quash = array();
     $csl_doc = new DOMDocument();
     if ($csl_doc->loadXML($csl)) {
         $style_nodes = $csl_doc->getElementsByTagName('style');
         if ($style_nodes) {
             foreach ($style_nodes as $style) {
                 $this->style = new csl_style($style);
             }
         }
         $info_nodes = $csl_doc->getElementsByTagName('info');
         if ($info_nodes) {
             foreach ($info_nodes as $info) {
                 $this->info = new csl_info($info);
             }
         }
         $this->locale = new csl_locale($lang);
         $this->locale->set_style_locale($csl_doc);
         $macro_nodes = $csl_doc->getElementsByTagName('macro');
         if ($macro_nodes) {
             $this->macros = new csl_macros($macro_nodes, $this);
         }
         $citation_nodes = $csl_doc->getElementsByTagName('citation');
         foreach ($citation_nodes as $citation) {
             $this->citation = new csl_citation($citation, $this);
         }
         $bibliography_nodes = $csl_doc->getElementsByTagName('bibliography');
         foreach ($bibliography_nodes as $bibliography) {
             $this->bibliography = new csl_bibliography($bibliography, $this);
         }
     }
 }
Example #30
0
File: Feed.php Project: horde/horde
 /**
  * Create a Feed object based on a DOMDocument.
  *
  * @param DOMDocument $doc The DOMDocument object to import.
  *
  * @throws Horde_Feed_Exception
  *
  * @return Horde_Feed_Base The feed object imported from $doc
  */
 public static function create(DOMDocument $doc, $uri = null)
 {
     // Try to find the base feed element or a single <entry> of an
     // Atom feed.
     if ($feed = $doc->getElementsByTagName('feed')->item(0)) {
         // Return an Atom feed.
         return new Horde_Feed_Atom($feed, $uri);
     } elseif ($entry = $doc->getElementsByTagName('entry')->item(0)) {
         // Return an Atom single-entry feed.
         $feeddoc = new DOMDocument($doc->version, $doc->actualEncoding);
         $feed = $feeddoc->appendChild($feeddoc->createElement('feed'));
         $feed->appendChild($feeddoc->importNode($entry, true));
         return new Horde_Feed_Atom($feed, $uri);
     }
     // Try to find the base feed element of an RSS feed.
     if ($channel = $doc->getElementsByTagName('channel')->item(0)) {
         // Return an RSS feed.
         return new Horde_Feed_Rss($channel, $uri);
     }
     // Try to find an outline element of an OPML blogroll.
     if ($outline = $doc->getElementsByTagName('outline')->item(0)) {
         // Return a blogroll feed.
         return new Horde_Feed_Blogroll($doc->documentElement, $uri);
     }
     // $doc does not appear to be a valid feed of the supported
     // types.
     throw new Horde_Feed_Exception('Invalid or unsupported feed format: ' . substr($doc->saveXML(), 0, 80) . '...');
 }