You are here

function _parser_common_syndication_atom10_parse_base_url in Feeds 7.2

Finds the base URL of an Atom document.

Parameters

SimpleXMLElement $xml: The XML document.

Return value

string|false Returns the base URL or false on failure.

1 call to _parser_common_syndication_atom10_parse_base_url()
_parser_common_syndication_atom10_parse in libraries/common_syndication_parser.inc
Parse atom feeds.

File

libraries/common_syndication_parser.inc, line 237
Downloading and parsing functions for Common Syndication Parser. Pillaged from FeedAPI common syndication parser.

Code

function _parser_common_syndication_atom10_parse_base_url(SimpleXMLElement $xml) {
  $base = $xml
    ->attributes('xml', TRUE)->base;
  if (!$base) {
    $base = $xml['base'];
  }
  if ($base && valid_url($base, TRUE)) {
    return rtrim($base, '/') . '/';
  }

  // Try to build a base from the self link.
  foreach ($xml
    ->xpath('*[local-name() = "link" and @rel="self" and @href]') as $self) {
    if (valid_url($self['href'], TRUE)) {
      return _parser_common_syndication_string_url_path((string) $self['href']);
    }
  }

  // Try to build a base from the alternate link.
  foreach ($xml
    ->xpath('*[local-name() = "link" and @rel="alternate" and @href]') as $alternate) {
    if (valid_url($alternate['href'], TRUE)) {
      return _parser_common_syndication_string_url_path((string) $alternate['href']);
    }
  }
  return FALSE;
}