You are here

function http_request_get_common_syndication in Feeds 7

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.2 libraries/http_request.inc \http_request_get_common_syndication()

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.

Return value

string - the discovered feed, FALSE - if the URL is not reachable or there no feeds.

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

File

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

Code

function http_request_get_common_syndication($url, $settings = NULL) {
  if (valid_url($url, TRUE)) {

    // Handle password protected feeds.
    $url_parts = parse_url($url);
    $password = $username = NULL;
    if (!empty($url_parts['user'])) {
      $password = $url_parts['pass'];
      $username = $url_parts['user'];
    }
  }
  $accept_invalid_cert = isset($settings['accept_invalid_cert']) ? $settings['accept_invalid_cert'] : FALSE;
  $download = http_request_get($url, $username, $password, $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;
    }
  }
}