You are here

function atomrdf_format_detect in Feeds Atom 6

Same name and namespace in other branches
  1. 7 libraries/atomrdf_parser.inc \atomrdf_format_detect()

Determine the feed format of a SimpleXML parsed object structure.

@todo This whole function coudl stand to be cleaned up.

Parameters

$xml: SimpleXML-preprocessed feed.

Return value

The feed format short description or FALSE if not compatible.

1 call to atomrdf_format_detect()
atomrdf_parser_parse in libraries/atomrdf_parser.inc
Parse the feed into a data structure.

File

libraries/atomrdf_parser.inc, line 41
Contains the atomrd parsing functions.

Code

function atomrdf_format_detect($xml) {
  if (!is_object($xml)) {
    return FALSE;
  }
  $attr = $xml
    ->attributes();
  $type = drupal_strtolower($xml
    ->getName());

  // If there are deleted-entry elements, then we know it's not just an Atom feed
  // but one with the Tombstone extension.
  if (in_array(FEEDS_ATOM_TOMBSTONE_NAMESPACE, $xml
    ->getDocNamespaces())) {
    $deleted_entry = $xml
      ->xpath('at:deleted-entry');
    if ($type == 'feed' && !empty($deleted_entry)) {
      return 'atom1.0';
    }
  }
  elseif ($type == 'feed' && !empty($xml->entry)) {
    return "atom1.0";
  }
  elseif ($type == "rss" && $attr["version"] == "2.0") {
    return "RSS2.0";
  }
  elseif ($type == "rdf" && isset($xml->channel)) {
    return "RDF";
  }
  elseif ($type == "rss" && $attr["version"] == "0.91") {
    return "RSS0.91";
  }
  elseif ($type == "rss" && $attr["version"] == "0.92") {
    return "RSS0.92";
  }
  return FALSE;
}