You are here

function feeds_oai_pmh_get_sets in Feeds OAI-PMH Fetcher and Parser 6

Same name and namespace in other branches
  1. 7 feeds_oai_pmh.inc \feeds_oai_pmh_get_sets()

Returns an array populated with the avaiable sets reported by an OAI-PMH endpoint.

1 call to feeds_oai_pmh_get_sets()
feeds_oai_pmh_identify in ./feeds_oai_pmh.inc
Returns an array of information returned by the OAI-PMH Identify verb.

File

./feeds_oai_pmh.inc, line 167

Code

function feeds_oai_pmh_get_sets($baseurl) {
  $sets = array();
  $url = "{$baseurl}?verb=ListSets";
  $result = drupal_http_request($url);

  // Return false on error
  if ($result->code != 200) {
    return FALSE;
  }
  $xml = simplexml_load_string($result->data);
  if (!$xml) {
    return FALSE;
  }
  if (isset($xml->error)) {
    return FALSE;
  }

  // Put set names into $sets array
  foreach ($xml->ListSets->set as $set) {
    $sets[(string) $set->setSpec]['name'] = (string) $set->setName;
    if ($set->setDescription) {

      // TODO: Use SimpleXML instead of regexp
      $description = $set->setDescription
        ->asXML();
      $description = preg_replace('/.*?<dc:description>([^<]+)<.dc:description.*/s', '\\1', $description);
      $sets[(string) $set->setSpec]['description'] = $description;
    }
  }
  return $sets;
}