You are here

function http_request_find_feeds in Feeds 7

Same name and namespace in other branches
  1. 8.2 libraries/http_request.inc \http_request_find_feeds()
  2. 6 libraries/http_request.inc \http_request_find_feeds()
  3. 7.2 libraries/http_request.inc \http_request_find_feeds()

Finds potential feed tags in the HTML document.

Parameters

string $html: The html string to search.

Return value

array() An array of href to feeds.

1 call to http_request_find_feeds()
http_request_get_common_syndication in libraries/http_request.inc
Discover RSS or atom feeds at the given URL. If document in given URL is an HTML document, function attempts to discover RSS or Atom feeds.

File

libraries/http_request.inc, line 267
Download via HTTP.

Code

function http_request_find_feeds($html) {
  $matches = array();
  preg_match_all(HTTP_REQUEST_PCRE_LINK_TAG, $html, $matches);
  $links = $matches[1];
  $candidates = array();
  $valid_links = array();

  // Build up all the links information.
  foreach ($links as $link_tag) {
    $attributes = array();
    $candidate = array();
    preg_match_all(HTTP_REQUEST_PCRE_TAG_ATTRIBUTES, $link_tag, $attributes, PREG_SET_ORDER);
    foreach ($attributes as $attribute) {

      // Find the key value pairs, attribute[1] is key and attribute[2] is the
      // value.
      if (!empty($attribute[1]) && !empty($attribute[2])) {
        $candidate[drupal_strtolower($attribute[1])] = drupal_strtolower(decode_entities($attribute[2]));
      }
    }

    // Examine candidate to see if it s a feed.
    // @TODO: could/should use http_request_is_feed ??
    if (isset($candidate['rel']) && $candidate['rel'] == 'alternate') {
      if (isset($candidate['href']) && isset($candidate['type']) && strpos($candidate['type'], 'xml') !== FALSE) {

        // All tests pass, its a valid candidate.
        $valid_links[] = $candidate['href'];
      }
    }
  }
  return $valid_links;
}