You are here

public static function Feed::findFeed in Feeds 8.3

Finds potential feed tags in an HTML document.

Parameters

string $url: The URL of the document, to use as a base URL.

string $html: The HTML document to search.

Return value

string|false The URL of the first feed link found, or false if unable to find a link.

1 call to Feed::findFeed()
Feed::getCommonSyndication in src/Utility/Feed.php
Discovers RSS or Atom feeds from a document.

File

src/Utility/Feed.php, line 70

Class

Feed
Helper functions for dealing with feeds.

Namespace

Drupal\feeds\Utility

Code

public static function findFeed($url, $html) {
  $use_error = libxml_use_internal_errors(TRUE);
  $entity_loader = libxml_disable_entity_loader(TRUE);
  $dom = new \DOMDocument();
  $status = $dom
    ->loadHTML(trim($html));
  libxml_disable_entity_loader($entity_loader);
  libxml_use_internal_errors($use_error);
  if (!$status) {
    return FALSE;
  }
  $feed_set = new FeedSet();
  $feed_set
    ->addLinks($dom
    ->getElementsByTagName('link'), $url);

  // Load the first feed type found.
  foreach ([
    'atom',
    'rss',
    'rdf',
  ] as $feed_type) {
    if (isset($feed_set->{$feed_type})) {
      return $feed_set->{$feed_type};
    }
  }
  return FALSE;
}