You are here

function http_request_get_common_syndication in Feeds 7.2

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

Discovers 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.

Parameters

string $url: The url of the feed to retrieve.

array $options: An optional array of options. For valid options, see feeds_http_request().

Return value

bool|string The discovered feed, or FALSE if the URL is not reachable or there was an error.

1 call to http_request_get_common_syndication()
FeedsHTTPFetcher::sourceFormValidate in plugins/FeedsHTTPFetcher.inc
Override parent::sourceFormValidate().

File

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

Code

function http_request_get_common_syndication($url, $options = array()) {
  $download = feeds_http_request($url, $options);

  // Cannot get the feed, return.
  // feeds_http_request() always returns 200 even if its 304.
  if ($download->code != 200) {
    return FALSE;
  }

  // Drop the data into a separate variable so all manipulations of the html
  // will not effect the actual object that exists in the static cache.
  // @see feeds_http_request()
  $downloaded_string = $download->data;

  // If this happens to be a feed then just return the url.
  if (isset($download->headers['content-type']) && http_request_is_feed($download->headers['content-type'], $downloaded_string)) {
    return $url;
  }
  $discovered_feeds = http_request_find_feeds($downloaded_string);
  foreach ($discovered_feeds as $feed_url) {
    $absolute = http_request_create_absolute_url($feed_url, $url);
    if (!empty($absolute)) {

      // @TODO: something more intelligent?
      return $absolute;
    }
  }
}