DOMXpath example


  public static function transformRootRelativeUrlsToAbsolute($html$scheme_and_host) {
    assert(empty(array_diff(array_keys(parse_url($scheme_and_host))["scheme", "host", "port"])), '$scheme_and_host contains scheme, host and port at most.');
    assert(isset(parse_url($scheme_and_host)["scheme"]), '$scheme_and_host is absolute and hence has a scheme.');
    assert(isset(parse_url($scheme_and_host)["host"]), '$base_url is absolute and hence has a host.');

    $html_dom = Html::load($html);
    $xpath = new \DOMXpath($html_dom);

    // Update all root-relative URLs to absolute URLs in the given HTML.     foreach (static::$uriAttributes as $attr) {
      foreach ($xpath->query("//*[starts-with(@$attr, '/') and not(starts-with(@$attr, '//'))]") as $node) {
        $node->setAttribute($attr$scheme_and_host . $node->getAttribute($attr));
      }
      foreach ($xpath->query("//*[@srcset]") as $node) {
        // @see https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset         // @see https://html.spec.whatwg.org/multipage/embedded-content.html#image-candidate-string         $image_candidate_strings = explode(',', $node->getAttribute('srcset'));
        $image_candidate_strings = array_map('trim', $image_candidate_strings);
        
if (!$locate->is_feed($file))
            {
                $copyStatusCode = $file->status_code;
                $copyContentType = $file->headers['content-type'];
                try
                {
                    $microformats = false;
                    if (class_exists('DOMXpath') && function_exists('Mf2\parse')) {
                        $doc = new DOMDocument();
                        @$doc->loadHTML($file->body);
                        $xpath = new DOMXpath($doc);
                        // Check for both h-feed and h-entry, as both a feed with no entries                         // and a list of entries without an h-feed wrapper are both valid.                         $query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '.
                            'contains(concat(" ", @class, " "), " h-entry ")]';
                        $result = $xpath->query($query);
                        $microformats = $result->length !== 0;
                    }
                    // Now also do feed discovery, but if microformats were found don't                     // overwrite the current value of file.                     $discovered = $locate->find($this->autodiscovery,
                                                $this->all_discovered_feeds);
                    
public function set_registry(SimplePie_Registry $registry)
    {
        $this->registry = $registry;
    }

    public function parse(&$data$encoding$url = '')
    {
        if (class_exists('DOMXpath') && function_exists('Mf2\parse')) {
            $doc = new DOMDocument();
            @$doc->loadHTML($data);
            $xpath = new DOMXpath($doc);
            // Check for both h-feed and h-entry, as both a feed with no entries             // and a list of entries without an h-feed wrapper are both valid.             $query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '.
                'contains(concat(" ", @class, " "), " h-entry ")]';
            $result = $xpath->query($query);
            if ($result->length !== 0) {
                return $this->parse_microformats($data$url);
            }
        }

        // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
if ($this->dom === null)
        {
            throw new SimplePie_Exception('DOMDocument not found, unable to use '.
                                          'locator');
        }
        if (!class_exists('DOMXpath'))
        {
            throw new SimplePie_Exception('DOMXpath not found, unable to use '.
                                          'get_rel_link');
        }

        $xpath = new DOMXpath($this->dom);
        $query = '//a[@rel and @href] | //link[@rel and @href]';
        foreach ($xpath->query($query) as $link)
        {
            $href = trim($link->getAttribute('href'));
            $parsed = $this->registry->call('Misc', 'parse_url', array($href));
            if ($parsed['scheme'] === '' ||
                preg_match('/^https?$/i', $parsed['scheme']))
            {
                if (method_exists($link, 'getLineNo') &&
                    $this->base_location < $link->getLineNo())
                {
                    

  protected function discoverResourceUrl($url) {
    try {
      $response = $this->httpClient->get($url);
    }
    catch (TransferException $e) {
      return FALSE;
    }

    $document = Html::load((string) $response->getBody());
    $xpath = new \DOMXpath($document);

    return $this->findUrl($xpath, 'json') ?: $this->findUrl($xpath, 'xml');
  }

  /** * Tries to find the oEmbed URL in a DOM. * * @param \DOMXPath $xpath * Page HTML as DOMXPath. * @param string $format * Format of oEmbed resource. Possible values are 'json' and 'xml'. * * @return bool|string * A URL to an oEmbed resource or FALSE if not found. */
Home | Imprint | This part of the site doesn't use cookies.