Discover feeds from the webpage's headers
@param  string $url
@return array
491064
public function discover(string $url) : array
    {
        $this->logger->info("discover feeds from {$url}");
        $stream = $this->client->getResponse($url, new \DateTime);

        $internalErrors = libxml_use_internal_errors(true);
        $entityLoaderDisabled = libxml_disable_entity_loader(true);

        $feeds = $this->extractFeeds($stream->getBody());

        libxml_use_internal_errors($internalErrors);
        libxml_disable_entity_loader($entityLoaderDisabled);

        return $feeds;
    }
798854
public function getBookTerms( $url ) {
		$terms = [];

		foreach ( [ 'front-matter-type', 'chapter-type', 'back-matter-type', 'glossary-type' ] as $taxonomy ) {
			// Handle request (local or global)
			$response = $this->handleGetRequest(
				$url, 'pressbooks/v2', "$taxonomy", [
					'per_page' => 25,
				]
			);

			if ( is_wp_error( $response ) ) {
				continue;
			}

			// Remove links
			unset( $response['_links'] );

			// Process response
			$terms = array_merge( $terms, $response );
		}

		if ( empty( $terms ) ) {
			$_SESSION['pb_errors'][] = sprintf( '<p>%1$s</p>', __( 'The source book&rsquo;s taxonomies could not be read.', 'pressbooks' ) );
		}

		return $terms;
	}
318778
public function url_get_contents($url) {

        $content = '';

		if (\function_exists('curl_exec')){
            $conn = \curl_init($url);
            \curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true);
            \curl_setopt($conn, CURLOPT_FRESH_CONNECT,  true);
            \curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
            \curl_setopt($conn,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
            \curl_setopt($conn, CURLOPT_AUTOREFERER, true);
            \curl_setopt($conn, CURLOPT_FOLLOWLOCATION, 1);
            \curl_setopt($conn, CURLOPT_VERBOSE, 0);
            $content = (\curl_exec($conn));
            \curl_close($conn);
        }
        if (!$content && \function_exists('file_get_contents')){
            $content = @\file_get_contents($url);
        }
        if (!$content && \function_exists('fopen') && function_exists('stream_get_contents')){
            $handle  = @\fopen ($url, "r");
            $content = @\stream_get_contents($handle);
        }
        return $content;
	}
290236
public function get(string $url, array $headers = [])
    {
        $ctx = $this->getContext('GET', null, $headers);
        $response = file_get_contents($url, false, $ctx);
        $this->saveCookies($http_response_header);

        return $response;
    }
500799
private function getRequestHeaders($url, array $parameters)
    {
        $headers = array();

        if (isset($this->clientId) && isset($this->sharedSecret)) {
            $objectIdentifier = null;
            if ($this->apiVersion === '1.1' && isset($parameters['id'])) {
                $objectIdentifier = $parameters['id'];
            } elseif ($this->apiVersion === '1.0' && isset($parameters['api_id'])) {
                $objectIdentifier = $parameters['api_id'];
            }

            $headers['X-Tulip-Client-ID'] = $this->clientId;
            $headers['X-Tulip-Client-Authentication'] = hash_hmac('sha256', $this->clientId.$url.$objectIdentifier, $this->sharedSecret);
        }

        return $headers;
    }
624209
static function GatherParams($url)
    {
        $reader = new StringReader($url);
        $param = '';
        $params = array();
        $start = false;
        while (false !== ($ch = $reader->ReadChar())) {
            if ($ch == '{') {
                $start = true;
            }
            else if ($ch == '}' && $start) {
                $params[] = $param;
                $param = '';
                $start = false;
            }
            else if ($start) {
                $param .= $ch;
            }
        }
        return $params;
    }
494990
private function parseArguments($url)
	{
		preg_match_all('~{(n:|a:|an:|w:|\*:|\?:)?([a-zA-Z0-9_]+)}~', $url, $matches);

		if (isset($matches[2]) && !empty($matches[2])) {
			return $matches[2];
		}

		return [];
	}
319092
private function getUriHostAndPath($url)
    {
        try {
            $uri = HttpUri::createFromString($url);
        } catch (InvalidArgumentException $e) {
            return ['', ''];
        }

        $host = $uri->getHost();
        $port = $uri->getPort();
        if (!$port && $uri->getScheme() == 'https') {
            $port = 443;
        }
        if ($port) {
            $host .= ':'.strval($port);
        }
        $path = $uri->getPath();
        if (!$path) {
            $path = '/';
        }

        return [$host, $path];
    }
100533
protected function _parseExtension($url)
    {
        if (count($this->_extensions) && strpos($url, '.') !== false) {
            foreach ($this->_extensions as $ext) {
                $len = strlen($ext) + 1;
                if (substr($url, -$len) === '.' . $ext) {
                    return [substr($url, 0, $len * -1), $ext];
                }
            }
        }

        return [$url, null];
    }
865459
public static function rssReader($url)
    {
        if (strpos($url, 'http') !== 0) {
            $url = 'http://'.$url;
        }

        $feed = self::curl($url);
        $xml = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA);

        return self::objectToArray($xml);
    }
1200530
public static function curlHeaders($url, &$data)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
        $data = curl_exec($ch);
        $headers = curl_getinfo($ch);
        curl_close($ch);

        return $headers;
    }
473734
protected function parseHeader($responseHeader)
    {

        $filtered = [];

        foreach ((array)$responseHeader as $header) {
            if (stripos($header, 'http/')) {
                $filtered = [];
            }
            $filtered[] = $header;
        }

        return $filtered;
    }
935403
static public function getHeaders($url)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
        curl_exec($ch);
        $headers = curl_getinfo($ch);
        curl_close($ch);

        return $headers;
    }
61536
final private function getTrafficData($feedUrl)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $feedUrl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);

        $xml = simplexml_load_string($response);

        return $this->sanitizeTrafficData($this->parseTrafficData($xml));
    }
1307605
protected function discover($url)
    {
        $endpoint = $this->findEndpointFromProviders($url);

        // if no provider was found, try to discover the endpoint URL
        if ($this->discovery && !$endpoint) {
            $discover = new Discoverer();
            $endpoint = $discover->getEndpointForUrl($url);
        }

        if (!$endpoint) {
            throw new \InvalidArgumentException('No oEmbed links found.');
        }

        return $endpoint;
    }
247663
static protected function fetchData(string $url): array {
        $url  .= '.json?key=' . urlencode(RC::get('redmineApiKey'));
        $data = file_get_contents($url);
        if ($data) {
            $data = (array) json_decode($data);
            $data = array_pop($data);
            return (array) $data;
        }
        throw new RuntimeException('Fetching data failed');
    }
1221756
public function fetch_feeds( $url = null ) {
		if ( ! $url ) {
			$url = $this->url;
		}
		if ( empty( $url ) ) {
			return new WP_Error( 'invalid-url', __( 'A valid URL was not provided.', 'indieweb-post-kinds' ) );
		}
		$fetch = $this->fetch( $url );
		if ( is_wp_error( $fetch ) ) {
			return $fetch;
		}
		// A feed was given
		if ( $this->content instanceof SimplePie ) {
			if ( ! class_exists( 'Parse_This_RSS', false ) ) {
				require_once plugin_dir_path( __FILE__ ) . '/class-parse-this-rss.php';
			}
			return array(
				'results' => array(
					array(
						'url'        => $url,
						'type'       => 'feed',
						'_feed_type' => Parse_This_RSS::get_type( $this->content ),
						'name'       => $this->content->get_title(),
					),
				),
			);
		}
		if ( $this->doc instanceof DOMDocument ) {
			$xpath = new DOMXPath( $this->doc );
			// Fetch and gather <link> data.
			$links = array();
			foreach ( $xpath->query( '(//link|//a)[@rel and @href]' ) as $link ) {
				$rel   = $link->getAttribute( 'rel' );
				$href  = $link->getAttribute( 'href' );
				$title = $link->getAttribute( 'title' );
				$type  = self::get_feed_type( $link->getAttribute( 'type' ) );
				if ( in_array( $rel, array( 'alternate', 'feed' ), true ) && ! empty( $type ) ) {
					$links[] = array_filter(
						array(
							'url'        => WP_Http::make_absolute_url( $href, $url ),
							'type'       => 'feed',
							'_feed_type' => $type,
							'name'       => $title,
						)
					);
				}
			}
			// Check to see if the current page is an h-feed
			$this->parse( array( 'feed' => true ) );
			if ( isset( $this->jf2['type'] ) && 'feed' === $this->jf2['type'] ) {
				$links[] = array_filter(
					array(
						'url'        => $url,
						'type'       => 'feed',
						'_feed_type' => 'microformats',
						'name'       => $this->jf2['name'],
					)
				);
			} elseif ( isset( $this->jf2['items'] ) ) {
				foreach ( $this->jf2['items'] as $item ) {
					if ( 'feed' === $item['type'] && isset( $item['uid'] ) ) {
						$links[] = array_filter(
							array(
								'url'        => $item['uid'],
								'type'       => 'feed',
								'_feed_type' => 'microformats',
								'name'       => ifset( $item['name'] ),
							)
						);
					}
				}
			}
			// Sort feeds by priority
			$rank = array(
				'jf2feed'      => 0,
				'microformats' => 1,
				'jsonfeed'     => 2,
				'atom'         => 3,
				'rss'          => 4,
			);
			usort(
				$links,
				function( $a, $b ) use ( $rank ) {
					return $rank[ $a['_feed_type'] ] > $rank[ $b['_feed_type'] ];
				}
			);

			return array( 'results' => $links );
		}
		return new WP_Error( 'unknown error', null, $this->content );
	}