You are here

function http_request_get_common_syndication in Feeds 6

Same name and namespace in other branches
  1. 8.2 libraries/http_request.inc \http_request_get_common_syndication()
  2. 7.2 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 $settings: An optional array of settings. Valid options are: accept_invalid_cert.

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 41
Download via HTTP.

Code

function http_request_get_common_syndication($url, $settings = NULL) {
  $accept_invalid_cert = isset($settings['accept_invalid_cert']) ? $settings['accept_invalid_cert'] : FALSE;
  $download = http_request_get($url, NULL, NULL, $accept_invalid_cert);

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

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

  // If this happens to be a feed then just return the url.
  if (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;
    }
  }
}