Exemple #1
1
 /**
  * {@inheritdoc}
  */
 public function apply(base $databox, Application $app)
 {
     $structure = $databox->get_structure();
     $DOM = new DOMDocument();
     $DOM->loadXML($structure);
     $xpath = new DOMXpath($DOM);
     foreach ($xpath->query('/record/subdefs/subdefgroup[@name="video"]/subdef[@name="preview"]/acodec') as $node) {
         $node->nodeValue = 'libvo_aacenc';
     }
     foreach ($xpath->query('/record/subdefs/subdefgroup[@name="video"]/subdef[@name="preview"]/vcodec') as $node) {
         $node->nodeValue = 'libx264';
     }
     $databox->saveStructure($DOM);
     $subdefgroups = $databox->get_subdef_structure();
     foreach ($subdefgroups as $groupname => $subdefs) {
         foreach ($subdefs as $name => $subdef) {
             $this->addScreenDeviceOption($subdefgroups, $subdef, $groupname);
             if (in_array($name, ['preview', 'thumbnail'])) {
                 if ($name == 'thumbnail' || $subdef->getSubdefType()->getType() != \Alchemy\Phrasea\Media\Subdef\Subdef::TYPE_VIDEO) {
                     $this->addMobileSubdefImage($subdefgroups, $subdef, $groupname);
                 } else {
                     $this->addMobileSubdefVideo($subdefgroups, $subdef, $groupname);
                 }
             }
             if ($subdef->getSubdefType()->getType() != \Alchemy\Phrasea\Media\Subdef\Subdef::TYPE_VIDEO) {
                 continue;
             }
             $this->addHtml5Video($subdefgroups, $subdef, $groupname);
         }
     }
     return true;
 }
Exemple #2
0
 public static function LINKS($url)
 {
     $content = file_get_contents($url);
     $doc = new \DOMDocument();
     $doc->loadHTML($content);
     // \bloc\application::instance()->log($doc);
     $xpath = new \DOMXpath($doc);
     $handle = curl_init("https://validator.nu/?level=error&doc={$url}&out=json");
     curl_setopt_array($handle, [CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT']]);
     $report = json_decode(curl_exec($handle));
     $number_of_errors = count($report->messages);
     $files = [['name' => 'index.html', 'content' => $content, 'type' => 'lang-html', 'url' => $url, 'report' => ['count' => count($report->messages), 'errors' => (new \bloc\types\Dictionary($report->messages))->map(function ($item) {
         return ['line' => $item->lastLine ?? 1, 'message' => $item->message];
     })]], ['name' => 'README', 'content' => null, 'type' => 'plain-text', 'url' => base64_encode($url . '/readme.txt')]];
     foreach ($xpath->query("//script[@src and not(contains(@src, 'http'))]") as $file) {
         $src = $file->getAttribute('src');
         $files[] = ['url' => base64_encode($url . '/' . $src), 'name' => substr($src, strrpos($src, '/') + 1), 'content' => null, 'type' => 'lang-js'];
     }
     foreach ($xpath->query("//link[not(contains(@href, 'http')) and contains(@href, '.css')]") as $file) {
         $src = $file->getAttribute('href');
         $uri = $url . '/' . $src;
         $code = substr(get_headers($uri)[0], 9, 3);
         if ($code < 400) {
             $report = json_decode(file_get_contents("https://jigsaw.w3.org/css-validator/validator?output=json&warning=0&profile=css3&uri=" . $uri));
             $count = $report->cssvalidation->result->errorcount;
         } else {
             $report = 'not-found';
             $count = "fix";
         }
         $files[] = ['url' => base64_encode($uri), 'name' => substr($src, strrpos($src, '/') + 1), 'content' => null, 'type' => 'lang-css', 'report' => ['count' => $count, 'errors' => (new \bloc\types\Dictionary($report->cssvalidation->errors ?? []))->map(function ($item) {
             return ['line' => $item->line, 'message' => $item->message];
         })]];
     }
     return $files;
 }
Exemple #3
0
 /**
  * Retreives a list of tags for a given resource that are marked
  * "Sujet principal". 
  * 
  * With the "non_principal_fallback" option set to TRUE, in the
  * event that there are no "sujet principal" tags, all the tags will
  * be used instead.
  *
  * (There should probably be a parameter for the string "Sujet
  * principal".)
  *
  * @param $url Optional. Defaults to current page.
  * @param $non_principal_fallback boolean Get all tags if there are NO "sujet principal".
  * @returns folksoPageDataMeta object
  */
 public function buildMeta($url = NULL, $max_tags = 0, $non_principal_fallback = NULL)
 {
     $mt = new folksoPageDataMeta();
     $this->getData($url);
     /** could set a maximum here, but instead we can
                                   set that at display time, since we might be 
                                   reusing data. 
     
                                   NB: if $url is NULL, getData() will use
                                   $this->url anyway.
                               **/
     if ($this->is_valid()) {
         $xpath = new DOMXpath($this->xml_DOM());
         // reusing existing DOM, maybe
         //$tag_princ is a DOMNodelist object
         $tag_princ = $xpath->query('//taglist/tag[metatag="Sujet principal"]');
         // 'Sujet principal' only
         if ($tag_princ->length > 0) {
             foreach ($tag_princ as $element) {
                 $tagname = $element->getElementsByTagName('display');
                 $mt->add_principal_keyword($tagname->item(0)->textContent);
             }
         }
         // All tags, when no 'sujet principal' is found.
         $all_tags = $xpath->query('//taglist/tag');
         if ($all_tags->length > 0) {
             foreach ($all_tags as $element) {
                 $tagname = $element->getElementsByTagName('display');
                 $mt->add_all_tags($tagname->item(0)->textContent);
             }
         }
         $this->mt = $mt;
         return $mt;
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function loadMetaValue($name, $default = NULL)
 {
     switch ($name) {
         case 'thumbnail':
             return sprintf(self::PREVIEW_IMAGE_URL, $this->lastId);
             break;
         case 'tags':
             $elements = $this->xpath->query(self::$XPATHS[$name]);
             if (!is_null($elements) && $elements->length > 0) {
                 $tags = array();
                 foreach ($elements as $element) {
                     $tags[] = $element->nodeValue;
                 }
                 return $tags;
             }
             break;
         default:
             if (!isset(self::$XPATHS[$name])) {
                 return $default;
             }
             $elements = $this->xpath->query(self::$XPATHS[$name]);
             if (!is_null($elements) && $elements->length > 0) {
                 return $elements->item(0)->nodeValue;
             }
     }
 }
 /**
  * main function extracts url data and returns json array
  * @return json array
  */
 public function getData()
 {
     $results = array();
     $total = 0;
     $htmlMain = $this->getHtml($this->url);
     $doc = new DOMDocument();
     @$doc->loadHTML($htmlMain['result']);
     $xpath = new DOMXpath($doc);
     $products = $xpath->query('//div[@class="productInfo"]');
     foreach ($products as $entry) {
         $htmlLinks = $entry->getElementsByTagName("a");
         foreach ($htmlLinks as $item) {
             $href = $item->getAttribute("href");
             $link = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
             $html = $this->getHtml($href);
             $doc = new DOMDocument();
             @$doc->loadHTML($html['result']);
             $xpath = new DOMXpath($doc);
             $productUnitPrice = $xpath->query('//p[@class="pricePerUnit"]');
             foreach ($productUnitPrice as $itemPrice) {
                 $unitPrice = preg_replace('/[^0-9.]*/', '', $itemPrice->nodeValue);
                 break;
             }
             $productText = $xpath->query('//div[@class="productText"]');
             foreach ($productText as $itemText) {
                 $description = trim($itemText->nodeValue);
                 break;
             }
             $results['result'][] = array('title' => $link, 'size' => $html['size'], 'unit_price' => $unitPrice, 'description' => $description);
             $total += $unitPrice;
         }
     }
     $results['total'] = $total;
     return json_encode($results);
 }
Exemple #6
0
function getStats($manifestfile, $resultsfile)
{
    //At the moment just read the manifest into an array
    //$urls = file($manifestfile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    //Filename will point to the text file but want to read the mfx file
    $folder = pathinfo($manifestfile, PATHINFO_DIRNAME);
    $base = pathinfo($manifestfile, PATHINFO_FILENAME);
    $mfx = "{$folder}/{$base}.mfx";
    $fp = @fopen($mfx, "r");
    //Read the first $headerlength bytes as the header
    $headerlength = 20;
    list($reclen, $totrecs) = explode(":", fread($fp, $headerlength));
    fclose($fp);
    //Open and load the required
    if ($resultsfile) {
        $doc = new DOMDocument();
        $ok = @$doc->load($resultsfile);
        if ($ok) {
            $x = new DOMXpath($doc);
            $answerlist = $x->query("/responses/response");
            $answers = $answerlist->length;
            $contributions = $x->query("/responses/response[@userid='{$userid}']");
            $yes = $x->query("/responses/response[@userid='{$userid}' and @answer='1']");
            $no = $x->query("/responses/response[@userid='{$userid}' and @answer='-1']");
            $dn = $x->query("/responses/response[@userid='{$userid}' and @answer='0']");
            echo json_encode(array(total => $totrecs, answers => $answers, contributions => $contributions->length, yes => $yes->length, no => $no->length, dontknow => $dn->length));
        } else {
            echo json_encode(array(total => $totrecs, answers => 0, contributions => 0));
        }
    } else {
        echo json_encode(array(total => $totrecs, answers => 0, contributions => 0));
    }
}
function outputScrape($url)
{
    $returnvalue = "";
    $data1 = preg_replace('#(<\\/ul>\\s*)+#i', '</ul>', scrapePage($url));
    $data1a = str_replace('files//', 'http://resources21.org/cl/files/', $data1);
    $data2 = preg_replace(array('/<head>(.*)<\\/head>/iUs', '/<html>/', '/<\\/html>/', '/<body>/', '/<\\/body>/', '/<\\/td><td>/'), "", $data1a);
    $returnvalue .= '<div id="lessonplan-content">';
    $doc = new DOMDocument();
    $doc->loadHTML($data2);
    libxml_use_internal_errors(false);
    $xpath = new DOMXpath($doc);
    $elements = $xpath->query('//ul');
    $elementsh = $xpath->query("//*[@class='secHed']");
    $header = array();
    if (!is_null($elementsh)) {
        foreach ($elementsh as $elementh) {
            $header[] = "<h3>" . $elementh->nodeValue . "</h3>";
        }
    }
    if (!is_null($elements)) {
        $i = 0;
        foreach ($elements as $element) {
            $returnvalue .= '<div id="' . $element->getAttribute('id') . '">' . $header[$i] . "<ul>";
            $nodes = $element->childNodes;
            foreach ($nodes as $node) {
                $returnvalue .= '<li>' . innerXML($node) . "</li>\n";
            }
            $returnvalue .= "</ul></div>";
            $i++;
        }
        $returnvalue .= "</div>";
    }
    // $returnvalue = "<[CDATA[ " . $returnvalue ." ]]>";
    return $returnvalue;
}
 public function parseResults($html)
 {
     $dom = new DOMDocument();
     $dom->loadHTML($html);
     $xpath = new DOMXpath($dom);
     $elements = $xpath->query('//*[@id="nav-wrapper"]/div[2]/div/section/div/div/div[2]/div');
     $results = array();
     if (!is_null($elements)) {
         foreach ($elements as $element) {
             $str = preg_replace('/\\s+/', ' ', trim($element->nodeValue));
             preg_match('/(.*)\\s\\|\\s([a-zA-Z0-9 \\-]+).*\\s([0-9,]+).*/', $str, $matches);
             // Get product url
             $itemurl = $xpath->query('div/div/h4/a', $element);
             foreach ($itemurl as $node) {
                 $url = $node->getAttribute('href');
             }
             // Get image
             $imagenodes = $xpath->query('div/a/img', $element);
             foreach ($imagenodes as $node) {
                 $image = $node->getAttribute('src');
             }
             array_push($results, array('title' => trim($matches[1]), 'platform' => $matches[2], 'price' => $matches[3], 'url' => '//magixbuttons.com' . $url, 'img' => $image));
         }
     }
     return $results;
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $metadata = $manager->getClassMetaData(get_class(new Operator()));
     $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $i = 1;
     $file = dirname(__FILE__) . '/../../operators.xml';
     $doc = new \DOMDocument();
     $doc->load($file);
     $xpath = new \DOMXpath($doc);
     $elements = $xpath->query('/operators/operator');
     if (!is_null($elements)) {
         /** @var $element DOMNode */
         foreach ($elements as $element) {
             $operator = new Operator();
             $operator->setId($i);
             $operator->setType($this->getTypeForString($element->getAttribute('type')));
             $operator->setOperator($element->getAttribute('operator'));
             $operator->setInputType($element->getAttribute('inputType'));
             // translations
             $translations = $xpath->query('translations/translation', $element);
             $this->processTranslations($manager, $operator, $translations);
             // values
             $values = $xpath->query('values/value', $element);
             $this->processValues($manager, $xpath, $operator, $values);
             $manager->persist($operator);
             ++$i;
         }
     }
     $manager->flush();
 }
 private function parseResults($html)
 {
     $dom = new DOMDocument();
     $dom->loadHTML($html);
     $xpath = new DOMXpath($dom);
     $elements = $xpath->query('//*[@id="middenkolom"]/div/table/tbody/tr');
     $results = array();
     if (!is_null($elements)) {
         foreach ($elements as $element) {
             // Get image
             foreach ($xpath->query('td[1]/a/img', $element) as $image) {
                 $imageUrl = 'http://www.nedgame.nl' . $image->getAttribute('src');
             }
             // Get link & title
             foreach ($xpath->query('td[2]/a', $element) as $link) {
                 $url = $link->getAttribute('href');
                 $title = $link->nodeValue;
             }
             // Get price
             foreach ($xpath->query('td[3]/div/div[4]', $element) as $prices) {
                 preg_match('/([0-9,\\-]+)/', $prices->nodeValue, $matches);
                 $price = $matches[0];
             }
             // Get platform
             foreach ($xpath->query('td[2]/span', $element) as $details) {
                 preg_match('/Platform: (.*)Type:/', $details->nodeValue, $matches);
                 $platform = $matches[1];
             }
             $results[] = array('title' => $title, 'url' => $url, 'img' => $imageUrl, 'platform' => $platform, 'price' => $price);
         }
         return $results;
     }
 }
function parseXmlStream($content, $field_mapping)
{
    $res = array();
    $xml = new DOMDocument();
    $xml->loadXML($content);
    $xpath = new DOMXpath($xml);
    $rootNamespace = $xml->lookupNamespaceUri($xml->namespaceURI);
    $xpath->registerNamespace('x', $rootNamespace);
    foreach ($field_mapping as $skey => $sval) {
        $path = preg_replace("/\\/([a-zA-Z])/", "/x:\$1", $skey);
        $elements = $xpath->query($path);
        if (!is_null($elements)) {
            $ele_cnt = 1;
            foreach ($elements as $element) {
                foreach ($sval as $field => $innerpath) {
                    $ipath = preg_replace(array("/^([a-zA-Z])/", "/\\/([a-zA-Z])/"), array("x:\$1", "/x:\$1"), $innerpath);
                    $val = $xpath->query($ipath, $element)->item(0)->textContent;
                    if ($val) {
                        $field_details = explode(':', $field);
                        $res[$field_details[0]][$ele_cnt][$field_details[1]] = $val;
                    }
                }
                $ele_cnt++;
            }
        }
    }
    return $res;
}
 function get_play_store()
 {
     $remote = array();
     $store_page = new DOMDocument();
     $internalErrors = libxml_use_internal_errors(true);
     $store_page->loadHTMLFile("https://play.google.com/store/search?q=awareframework%20plugin");
     $xpath = new DOMXpath($store_page);
     $packages_titles = $xpath->query('//a[@class="title"]/@href');
     foreach ($packages_titles as $pkgs) {
         $package_name = substr($pkgs->textContent, strrpos($pkgs->textContent, "=") + 1, strlen($pkgs->textContent));
         preg_match("/^com\\.aware\\.plugin\\..*/", $package_name, $matches, PREG_OFFSET_CAPTURE);
         if (count($matches) == 0) {
             continue;
         }
         $package_page = new DOMDocument();
         $package_page->loadHTMLFile("https://play.google.com/store/apps/details?id={$package_name}");
         $xpath = new DOMXpath($package_page);
         $icon = $xpath->query('//img[@class="cover-image"]/@src');
         $version = $xpath->query('//div[@itemprop="softwareVersion"]');
         $description = $xpath->query('//div[@itemprop="description"]');
         $pkg = array('title' => trim($pkgs->parentNode->textContent), 'package' => $package_name, 'version' => trim($version->item(0)->textContent), 'desc' => $description->item(0)->childNodes->item(1)->nodeValue, 'iconpath' => 'https:' . $icon->item(0)->value, 'first_name' => 'AWARE', 'last_name' => 'Framework', 'email' => 'aware@comag.oulu.fi');
         $remote[] = $pkg;
     }
     return $remote;
 }
Exemple #13
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)];
 }
 /**
  * @return string
  */
 public function getRemoteId()
 {
     $videoIdNode = $this->xpath->query("//*/item_status/id[@type='video_id']")->item(0);
     if (is_null($videoIdNode)) {
         return null;
     }
     return $videoIdNode->nodeValue;
 }
 public function getVideoId()
 {
     $reference = $this->xpath->query("//*/id[@type='Video ID']")->item(0);
     if ($reference) {
         return $reference->nodeValue;
     }
     return null;
 }
Exemple #16
0
 public function __construct($bible)
 {
     $this->bible = $bible;
     $this->currentParagraphStyle = "";
     $this->currentParagraphContent = "";
     $this->currentTextStyle = array();
     $this->frameCount = 0;
     $this->noteCount = 0;
     $this->currentNoteTextStyle = array();
     $database_config_general = Database_Config_General::getInstance();
     $database_config_bible = Database_Config_Bible::getInstance();
     $template = dirname(__FILE__) . "/template.odt";
     $this->unpackedOdtFolder = Filter_Archive::unzip($template, false);
     Filter_Rmdir::rmdir($this->unpackedOdtFolder . "/Configurations2");
     $this->contentDom = new DOMDocument();
     $this->contentDom->load($this->unpackedOdtFolder . "/content.xml");
     $contentXpath = new DOMXpath($this->contentDom);
     $this->officeTextDomNode = $contentXpath->query("office:body/office:text")->item(0);
     // Remove the default content from the template. This is a text:p element.
     $node = $contentXpath->query("text:p", $this->officeTextDomNode)->item(0);
     $this->officeTextDomNode->removeChild($node);
     $this->createdStyles = array();
     $this->stylesDom = new DOMDocument();
     $this->stylesDom->load($this->unpackedOdtFolder . "/styles.xml");
     $stylesXpath = new DOMXpath($this->stylesDom);
     $this->officeStylesDomNode = $stylesXpath->query("office:styles")->item(0);
     // Set the page size and margins.
     $pageLayoutProperties = $stylesXpath->query("descendant::style:page-layout-properties")->item(0);
     $pageLayoutProperties->setAttribute("fo:page-width", $database_config_bible->getPageWidth($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:page-height", $database_config_bible->getPageHeight($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-left", $database_config_bible->getInnerMargin($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-right", $database_config_bible->getOuterMargin($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-top", $database_config_bible->getTopMargin($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-bottom", $database_config_bible->getBottomMargin($this->bible) . "mm");
     // Update the tab-stops in the relevant header styles. The tab stops depend on page and margin dimensions.
     $nodeList = $stylesXpath->query("descendant::style:style[contains(attribute::style:parent-style-name,'Header')]//descendant::style:tab-stop");
     $centerPosition = $database_config_bible->getPageWidth($this->bible) - $database_config_bible->getInnerMargin($this->bible) - $database_config_bible->getOuterMargin($this->bible);
     $centerPosition /= 2;
     $counter = 0;
     foreach ($nodeList as $node) {
         $modulus = $counter % 2;
         $node->setAttribute("style:position", $centerPosition * ($modulus + 1) . "mm");
         $counter++;
     }
     // Remove the date style for the running headers, so that it takes the default style.
     $numberDateStyleNode = $stylesXpath->query("descendant::number:date-style")->item(0);
     $numberDateStyleNode->parentNode->removeChild($numberDateStyleNode);
     // Whether and how to put the date in the running headers.
     $nodeList = $stylesXpath->query("descendant::text:date");
     foreach ($nodeList as $node) {
         if ($database_config_bible->getDateInHeader($this->bible)) {
             $node->removeAttribute("text:date-value");
             $node->nodeValue = "";
         } else {
             $node->parentNode->removeChild($node);
         }
     }
 }
function casValidate($cas)
{
    $service = SimpleSAML_Utilities::selfURL();
    $service = preg_replace("/(\\?|&)?ticket=.*/", "", $service);
    # always tagged on by cas
    /**
     * Got response from CAS server.
     */
    if (isset($_GET['ticket'])) {
        $ticket = urlencode($_GET['ticket']);
        #ini_set('default_socket_timeout', 15);
        if (isset($cas['validate'])) {
            # cas v1 yes|no\r<username> style
            $paramPrefix = strpos($cas['validate'], '?') ? '&' : '?';
            $result = SimpleSAML_Utilities::fetch($cas['validate'] . $paramPrefix . 'ticket=' . $ticket . '&service=' . urlencode($service));
            $res = preg_split("/\r?\n/", $result);
            if (strcmp($res[0], "yes") == 0) {
                return array($res[1], array());
            } else {
                throw new Exception("Failed to validate CAS service ticket: {$ticket}");
            }
        } elseif (isset($cas['serviceValidate'])) {
            # cas v2 xml style
            $paramPrefix = strpos($cas['serviceValidate'], '?') ? '&' : '?';
            $result = SimpleSAML_Utilities::fetch($cas['serviceValidate'] . $paramPrefix . 'ticket=' . $ticket . '&service=' . urlencode($service));
            $dom = DOMDocument::loadXML($result);
            $xPath = new DOMXpath($dom);
            $xPath->registerNamespace("cas", 'http://www.yale.edu/tp/cas');
            $success = $xPath->query("/cas:serviceResponse/cas:authenticationSuccess/cas:user");
            if ($success->length == 0) {
                $failure = $xPath->evaluate("/cas:serviceResponse/cas:authenticationFailure");
                throw new Exception("Error when validating CAS service ticket: " . $failure->item(0)->textContent);
            } else {
                $attributes = array();
                if ($casattributes = $cas['attributes']) {
                    # some has attributes in the xml - attributes is a list of XPath expressions to get them
                    foreach ($casattributes as $name => $query) {
                        $attrs = $xPath->query($query);
                        foreach ($attrs as $attrvalue) {
                            $attributes[$name][] = $attrvalue->textContent;
                        }
                    }
                }
                $casusername = $success->item(0)->textContent;
                return array($casusername, $attributes);
            }
        } else {
            throw new Exception("validate or serviceValidate not specified");
        }
        /**
         * First request, will redirect the user to the CAS server for authentication.
         */
    } else {
        SimpleSAML_Logger::info("AUTH - cas-ldap: redirecting to {$cas['login']}");
        SimpleSAML_Utilities::redirectTrustedURL($cas['login'], array('service' => $service));
    }
}
function query_geonames($place)
{
    $xmlDoc = new DOMDocument();
    $xmlDoc->load('http://api.geonames.org/search?q=' . $place . '&maxRows=10&username=anscoins&style=full');
    $xpath = new DOMXpath($xmlDoc);
    $geonameId = $xpath->query('descendant::geonameId')->item(0)->nodeValue;
    $name = $xpath->query('descendant::name')->item(0)->nodeValue . ' (' . $xpath->query('descendant::countryName')->item(0)->nodeValue . ')';
    $geonames = array($geonameId, $name);
    return $geonames;
}
 /**
  * Parses weblog node and sets weblog object.
  *
  * @return  void
  */
 protected function parseWeblog()
 {
     // weblog object field
     $result = $this->xpath->query('./weblog', $this->dom);
     if ($result->length == 1) {
         $this->weblog = new Weblog($result->item(0));
     } else {
         $this->weblog = null;
     }
 }
Exemple #20
0
 /**
  * Get elements
  *
  * @param string $path
  * @return \DOMNodeList
  */
 public function getElements($path, \DOMElement $contextNode = null)
 {
     if ($this->dom === null) {
         return array();
     }
     if ($this->xpath === null) {
         $this->xpath = new \DOMXpath($this->dom);
     }
     return $this->xpath->query($path, $contextNode);
 }
Exemple #21
0
 /**
  * Get node list
  *
  * @param string $path
  * @param string $file
  * @return \DOMNodeList
  */
 public function getNodeList($path, $file = 'word/document.xml')
 {
     if ($this->dom === null || $file !== $this->file) {
         $this->getFileDom($file);
     }
     if (null === $this->xpath) {
         $this->xpath = new \DOMXpath($this->dom);
     }
     return $this->xpath->query($path);
 }
Exemple #22
0
function check_ewus($username, $password, $pac_pesel)
{
    $params = array('credentials' => array(array('name' => 'domain', 'value' => array('stringValue' => '07')), array('name' => 'login', 'value' => array('stringValue' => $username))), 'password' => $password);
    try {
        $clientAuth = new SoapClient('https://ewus.nfz.gov.pl/ws-broker-server-ewus/services/Auth?wsdl', array('trace' => true));
        $clientAuth->__soapCall('login', array($params), null, null, $loginHeaders);
        $date = date('Y-m-d\\TH:i:s.BP');
        $xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://xml.kamsoft.pl/ws/common" xmlns:brok="http://xml.kamsoft.pl/ws/broker">
    <soapenv:Header>
    <com:session id="' . $loginHeaders['session']->id . '" xmlns:ns1="http://xml.kamsoft.pl/ws/common"/>
    <com:authToken id="' . $loginHeaders['authToken']->id . '" xmlns:ns1="http://xml.kamsoft.pl/ws/common"/>
    </soapenv:Header>
    <soapenv:Body>
    <brok:executeService>
    <com:location>
    <com:namespace>nfz.gov.pl/ws/broker/cwu</com:namespace>
    <com:localname>checkCWU</com:localname>
    <com:version>2.0</com:version>
    </com:location>
    <brok:date>' . $date . '</brok:date>
    <brok:payload>
    <brok:textload>
    <ewus:status_cwu_pyt xmlns:ewus="https://ewus.nfz.gov.pl/ws/broker/ewus/status_cwu/v2">
    <ewus:numer_pesel>' . $pac_pesel . '</ewus:numer_pesel>
    <ewus:system_swiad nazwa="eWUS" wersja="2.0"/>
    </ewus:status_cwu_pyt>
    </brok:textload>
    </brok:payload>
    </brok:executeService>
    </soapenv:Body>
    </soapenv:Envelope>';
        $clientBroker = new SoapClient('https://ewus.nfz.gov.pl/ws-broker-server-ewus/services/ServiceBroker?wsdl', array('trace' => true, 'exceptions' => true));
        $r = $clientBroker->__doRequest($xml, 'https://ewus.nfz.gov.pl/ws-broker-server-ewus/services/ServiceBroker', 'executeService', SOAP_1_1);
        $doc = new DOMDocument();
        $doc->loadXML($r);
        $blad = $doc->getElementsByTagName('faultstring')->item(0);
        if ($blad != '') {
            return $blad->nodeValue;
        } else {
            $match = $doc->getElementsByTagName('status_cwu_odp');
            $foundXML = $doc->saveXML($match->item(0));
            $xpath = new DOMXpath($doc);
            $xpath->registerNamespace('odp', 'https://ewus.nfz.gov.pl/ws/broker/ewus/status_cwu/v2');
            $ewus_odp['nr_potw'] = $xpath->query("//odp:status_cwu_odp")->item(0)->getAttribute('id_operacji');
            $ewus_odp['potwierdzenie'] = $foundXML;
            $elements = $xpath->query("//odp:status_ubezp");
            $ewus_odp['status'] = $elements->item(0)->nodeValue;
            $ewus_odp['data'] = date('Y-m-d');
            return $ewus_odp;
        }
    } catch (Exception $e) {
        return $e->faultstring;
    }
}
 /**
  *
  */
 protected function setRequestCriteria()
 {
     // $obj = simplexml_load_string($this->requestNode->saveXML($this->requestNode));
     $xpath = new DOMXpath($this->requestNode);
     $this->validateCriteriaElements($xpath->query("//search_criteria/criteria"));
     $this->setGlobalCriteria($this->requestNode);
     $this->setValueCriteria($xpath->query("//search_criteria/criteria[type/text() = 'value']"));
     $this->setRangeCriteria($xpath->query("//search_criteria/criteria[type/text() = 'range']"));
     $this->setResponseColumnsCriteria($xpath->query("//response_columns"));
     $this->criteria['global']['response_format'] = 'xml';
 }
function parse_rss($data)
{
    $dom = new DomDocument();
    $dom->loadXML($data);
    $feeds = array();
    $xpath = new DOMXpath($dom);
    foreach ($xpath->query("/rss/channel/item") as $item) {
        $pub_date = $xpath->query("pubDate/text()", $item)->item(0)->wholeText;
        $pub_date = DateTime::createFromFormat(DateTime::RSS, $pub_date);
        array_push($feeds, array("title" => $xpath->query("title/text()", $item)->item(0)->wholeText, "description" => $xpath->query("description/text()", $item)->item(0)->wholeText, "link" => $xpath->query("link/text()", $item)->item(0)->wholeText, "pub_date" => $pub_date));
    }
    return $feeds;
}
 private static function ogParse($data)
 {
     libxml_use_internal_errors(true);
     $url = $data->entities->urls[0]->expanded_url;
     // In case URL using short URL
     $url = self::shortUrlParse($url);
     $doc = new \DOMDocument();
     $doc->loadHTMLFile($url);
     $xpath = new \DOMXpath($doc);
     $ogImageTag = $xpath->query("*/meta[@property='og:image']")->item(0);
     $ogTitleTag = $xpath->query("*/meta[@property='og:title']")->item(0);
     $ogDescriptionTag = $xpath->query("*/meta[@property='og:description']")->item(0);
     $result = ['tweet_id' => $data->id, 'screen_name' => $data->user->screen_name, 'title' => $ogTitleTag->attributes->getNamedItem('content')->nodeValue, 'image' => $ogImageTag->attributes->getNamedItem('content')->nodeValue, 'description' => $ogDescriptionTag->attributes->getNamedItem('content')->nodeValue, 'url' => $url, 'retweet' => $data->retweet_count, 'favorite' => $data->favorite_count];
     return $result;
 }
function parse_selector_values_by_name($name, $selector_html, $encoding = 'UTF-8')
{
    $dom = new DOMDocument('1.0', $encoding);
    $dom->loadHTML($selector_html);
    $xpath = new DOMXpath($dom);
    $options = $xpath->query("*/select/option");
    $options = $xpath->query("*/select[@name='" . $name . "']/option");
    $result = array();
    foreach ($options as $option) {
        $optionValue = $option->getAttribute('value');
        $optionContent = $option->nodeValue;
        $result[$optionValue] = $optionContent;
    }
    return (array) $result;
}
Exemple #27
0
 function _list()
 {
     error_reporting(E_ALL);
     list($code, $body) = $this->_request('status');
     $d = new DOMDocument();
     $d->loadXML($body);
     $xp = new DOMXpath($d);
     foreach ($xp->query('//language') as $c) {
         $name = $code = '';
         foreach ($c->childNodes as $n) {
             switch (strtolower($n->nodeName)) {
                 case 'name':
                     $name = $n->textContent;
                     break;
                 case 'code':
                     $code = $n->textContent;
                     break;
             }
         }
         if (!$code) {
             continue;
         }
         $this->stdout->write(sprintf("%s (%s)\n", $code, $name));
     }
 }
Exemple #28
0
 /**
  * 
  */
 public function rerender()
 {
     $cssFileContent = '';
     $components = $this->uiComposer->getUiComponents();
     //Get all CSS file content
     foreach ($components as $component) {
         //TODO: check renderresult instead of component type
         if ($component instanceof HtmlWidget) {
             $cssFileContent .= $component->getRenderResult()->cssFileContent;
         }
     }
     if (trim($cssFileContent)) {
         // build file
         $cssFileContent = $this->minify($cssFileContent);
         $httpFileNamePath = '/generated/' . md5($cssFileContent) . '.css';
         $fileNamePath = 'public' . $httpFileNamePath;
         if (!file_exists($fileNamePath)) {
             file_put_contents($fileNamePath, $cssFileContent);
         }
         // get $doc and add the href
         $doc = $this->uiComposer->getDoc();
         //TODO: use composer xpath?
         $xPath = new \DOMXpath($this->uiComposer->getDoc());
         $linkElement = $xPath->query('//link[@id="css-file"]');
         //TODO url function missing
         $linkElement->item(0)->setAttribute('href', FC::assetLink($httpFileNamePath));
     }
     $this->needsRerender = false;
 }
Exemple #29
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     // force id = 1
     $metadata = $manager->getClassMetaData(get_class(new SecurityType()));
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $file = $this->container->getParameter('sulu_security.security_types.fixture');
     $doc = new \DOMDocument();
     $doc->load($file);
     $xpath = new \DOMXpath($doc);
     $elements = $xpath->query('/security-types/security-type');
     if (!is_null($elements)) {
         /** @var $element \DOMNode */
         foreach ($elements as $element) {
             $securityType = new SecurityType();
             $children = $element->childNodes;
             /** @var $child \DOMNode */
             foreach ($children as $child) {
                 if (isset($child->nodeName)) {
                     if ($child->nodeName == 'id') {
                         $securityType->setId($child->nodeValue);
                     }
                     if ($child->nodeName == 'name') {
                         $securityType->setName($child->nodeValue);
                     }
                 }
             }
             $manager->persist($securityType);
         }
     }
     $manager->flush();
 }
 protected function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $dElements = array(0 => array(1), 1 => array(2), 2 => array(3), 3 => array(4), 4 => array(5));
     $arr = array();
     foreach ($dElements as $dId => $dArr) {
         $dayMenu = '';
         foreach ($dArr as $dRow) {
             $element = $xpath->query('/html/body/div[2]/div[2]/article/div/div/p[' . $dRow . ']');
             foreach ($element as $e) {
                 $dayMenuExploded = explode(PHP_EOL, $e->nodeValue);
                 $foodArray = array();
                 foreach ($dayMenuExploded as $foods) {
                     $foods = parent::cleanStr($foods);
                     if (!empty($foods)) {
                         $foodArray[] = preg_replace('/([\\t0-9, ]+$)/', '', $foods);
                     }
                 }
                 $dayMenu = implode(' / ', $foodArray);
             }
         }
         $weekDay = parent::weekNumToText($dId);
         $arr[$weekDay] = parent::fixSpaces(preg_replace('/[0-9, ]+$/', '', $dayMenu));
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }